Home > database >  How can i add tow property in my model in EF code first from one model?
How can i add tow property in my model in EF code first from one model?

Time:05-29

I want to add two properties from the city model:

after migration this error shows up:

Unable to determine the relationship represented by navigation 'City.Orders' of type 'ICollection'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.

here is my code :

public class Order
{
    public virtual City FromCity { get; set; }
    public virtual City ToCity { get; set; }
}

public class City
{
    public int Id { get; set; }
    public string Name { get; set; }
    public virtual ICollection<Order> Orders { get; set; }
}

CodePudding user response:

I suppose your model is more complicated than just FromCity and ToCity because I don't think it's a good idea to store such information in a different table. Yet, You can use inheritance in this case.

The table-per-hierarchy (TPH) pattern is used by default to map the Relationship Diagram

  • Related