-1

this is class diagram of my application:

Class Diagram

when i want to run this simple code:

using (var db = new AppContext())
{
    var u1 = new User { firstName = "A", lastName = "B" };

    db.users.Add(u1);

    db.SaveChanges();
    Console.ReadLine();
}

this exception thrown:

Additional information: Unable to determine the principal end of an association between the types 'CodeFirstNewDataBase.Model.User' and 'CodeFirstNewDataBase.Model.User'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.

and i'm using Table per Hierarchy mapping in my project as you seen below:"

public class BaseEntityConfig : EntityTypeConfiguration<BaseEntity>
{
    public BaseEntityConfig()
    {
        this.Property(x => x.id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
    }
}

public class UserConfig : EntityTypeConfiguration<User>
{
    public UserConfig()
    {
        this.Map(m =>
        {
            m.MapInheritedProperties();
            m.ToTable("User");
        });
    }
}

how can i solve this problem?

i'm new to EF code first

Rasool Ghafari
  • 4,128
  • 7
  • 44
  • 71
  • possible duplicate of [What does principal end of an association means in 1:1 relationship in Entity framework](http://stackoverflow.com/questions/6531671/what-does-principal-end-of-an-association-means-in-11-relationship-in-entity-fr) – kodebot Mar 21 '15 at 16:39

1 Answers1

0

I generated model classes using the power tools and stated tweaking model classes and mapping per my need. Hope this helps https://msdn.microsoft.com/en-us/library/jj200620.aspx