2012-12-11 104 views
1

我对这种代码优先模式很新颖。 我创建了一个类,现在我想在我的数据库中创建一个表。 在PM控制台中,我写了'add migration addSummaries'并按回车。 和我有以下错误:创建一个新表实体框架代码第一模式

PM> add-migration addsummaries 
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(EdmEn titySet 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(DbDatabase Mapping 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() 
Value cannot be null. 
Parameter name: key 
PM> 

我不知道这是什么mean..can人帮助我找到实际的错误?

编辑:

public class Summary 
{ 
    [Key] 
    public int Id { get; set; } 

    public Guid SummaryId { get; set; } 

    [Required] 
    [Display(Name="Title")] 
    [MaxLength(500)] 
    public string SummaryTitle { get; set; } 

    [Display(Name = "Description")] 
    public string Description { get; set; } 

    public DateTime PublishDate { get; set; } 

    public virtual UserProfile Writer { get; set; } 

    public bool PublishStatus { get; set; } 

    [Required] 
    public DateTime LastActionDate { get; set; } 

    public HttpPostedFileBase DocumentFile { get; set; } 
    public string FileName { get; set; } 
    public string FileLocation { get; set; } 

    [Required] 
    public string Tag { get; set; } 

    public virtual ICollection<Course> Category { get; set; } 
} 
+0

你可以请发布该类的代码?你是否尝试过使用DbContext而不是控制台? – IronMan84

+0

你需要提供更多的信息。你实体POCO是什么样的? – khellang

+0

添加到问题 – kandroid

回答

2

如果从“摘要”类继承的类,它引用了未包含在你的DbContext anthor自定义类,你会遇到这个问题。

相关问题