1

I am quite new to this code-first pattern. I have created a class and now I want to create a table in my database. in the PM console i wrote 'add migration addSummaries' and hit enter. and i have the following error:

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> 

i have no clue what does it mean..can anybody help me to find the actual error??

EDIT:

 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
  • Can you please post the code for that class? Have you tried using the DbContext instead of the console? Commented Dec 11, 2012 at 21:37
  • You need to give more information that that. What does you entity POCO look like? Commented Dec 11, 2012 at 21:37
  • @IronMan84 I am not sure how to create table using DbContext..can u tell me plz? Commented Dec 11, 2012 at 21:44
  • Here's a tutorial: msdn.microsoft.com/en-us/data/gg192989.aspx Commented Dec 11, 2012 at 21:49

1 Answer 1

2

If you have a class inherited from the "Summary" class, and it references anthor custom class that is not contained in your DbContext, you will encounter this issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.