1

我对这种代码优先模式很陌生。我创建了一个类,现在我想在我的数据库中创建一个表。在 PM 控制台中,我编写了“添加迁移 addSummaries”并按 Enter。我有以下错误:

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> 

我不知道这是什么意思..有人可以帮我找到实际的错误吗?

编辑:

 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; }
}
4

1 回答 1

2

如果您有一个从“Summary”类继承的类,并且它引用了未包含在您的 DbContext 中的另一个自定义类,您将遇到此问题。

于 2013-08-02T01:23:07.883 回答