尽管创建了db,为什么CreateDatabaseIfNotExists不会创建关系

时间:2014-12-11 12:42:15

标签: c# entity-framework

我从我的edmx文件创建一个db,如下所示:

Database.SetInitializer(new CreateDatabaseIfNotExists<myEntities>());

创建了db。但是,缺少一个递归关系。它在edmx中,但不在db中。为什么它无法创建递归关系,我该如何解决?

通过recrusive关系,我指的是一个与自己有关系的表。

在myEntities类中,其中一个文件是:

public DbSet<Product> Products { get; set; }

在自动生成的文件中:

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

0 个答案:

没有答案
相关问题