问题
I create a db from my edmx file like this:
Database.SetInitializer(new CreateDatabaseIfNotExists<myEntities>());
And the db is created. However, there is one recursive relationship missing. It is in the edmx, but not in the db. Why does it fail to create a recursive relationship and how can I fix it?
By recrusive relationship I mean a table that has a relationship with itself.
In the myEntities class, one of the fileds is this:
public DbSet<Product> Products { get; set; }
And in an auto-generated file:
public partial class Product
{
public Product()
{
this.Product1 = new HashSet<Product>();
this.Products = new HashSet<Product>();
this.Ingredients = new HashSet<Ingredient>();
}
public int ProductId { get; set; }
public virtual ICollection<Product> Product1 { get; set; }
public virtual ICollection<Product> Products { get; set; }
public virtual ICollection<Ingredient> Ingredients { get; set; }
}
来源:https://stackoverflow.com/questions/27423193/why-dont-createdatabaseifnotexists-create-a-relationship-although-db-gets-creat