我有了Type類型的屬性的對象:EF代碼優先 - 型物業類型
public ScheduledJob
{
public int ID { get; set; }
public Type JobType { get; set; }
public string JobParameters { get; set; }
}
當我生成代碼優先遷移,我得到以下錯誤:
System.ArgumentNullException: Value cannot be null.
Parameter name: key
at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
at System.Data.Entity.ModelConfiguration.Configuration.Mapping.SortedEntityTypeIndex.Add(EdmEntitySet entitySet, EdmEntityType entityType)
at System.Data.Entity.ModelConfiguration.Configuration.Mapping.EntityMappingService.Analyze()
at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntityTypes(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.Configure(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.LazyInternalContext.get_CodeFirstModel()
at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer)
at System.Data.Entity.Migrations.Extensions.DbContextExtensions.<>c__DisplayClass1.<GetModel>b__0(XmlWriter w)
at System.Data.Entity.Migrations.Extensions.DbContextExtensions.GetModel(Action`1 writeXml)
at System.Data.Entity.Migrations.Extensions.DbContextExtensions.GetModel(DbContext context)
at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext)
at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator()
at System.Data.Entity.Migrations.Design.ToolingFacade.GetPendingMigrationsRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
使這個場景有效的最佳方式是什麼?
編輯爲@ NSGaga的帖子:
整個模型(簡體)是這樣的:
所有作業對象實現以下接口:
public interface IJob
{
Guid ID { get; set; }
void Run();
}
作業的每個人都有自己的屬性用作一種參數:
public class ProcessMedia : IJob
{
public Guid ID { get; set; }
public int MediaContentID { get; set; }
public void Run()
{
if(MediaContentID <= 0)
throw new Exception("Missing parameter MediaContentID");
//work
}
}
我將此模型用於異步作業處理系統,效果很好。現在,我試圖構建一個調度程序,在那裏我可以給它一個作業類型和參數(序列化爲字符串),並讓它按間隔運行。
將完全限定的類型名稱保存爲字符串。 –
我之前是這麼做的,我只是在檢查是否有捷徑。 –