简体   繁体   English

实体框架复杂关系

[英]Entity Framework complex relationship

I have class A which inherits from class B , at the same time class A has many instances of B . 我有从B类继承 ,同时类A有B的多个实例 Class B contains class A property as a reference. B类包含A类属性作为参考。

I'm looking for the best way to map this relationship using EF Codefirst. 我正在寻找使用EF Codefirst映射这种关系的最佳方法。

A is NOT inherited from B. They have a few common properties like this: A 不是从B继承的。它们具有一些通用属性,如下所示:

class ABCommon
{
    //common properties here
}

class B : ABCommon
{
    public virtual A A { get; set; }
    //this property makes everything crazy if A inherits from B
}

public A : ABCommon
{
    public virtual ICollection<B> Bs { get; set; }
}

It's just a simple 1-to-many relationship between A and B. 这只是A和B之间的简单一对多关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM