ClassMap 到抽象类的子类
我有以下域模型要使用 ClassMaps/SubclassMaps
A - HasMany -> 进行映射B(A 应该是表)
B 在代码中是抽象的(并且不应该是表)
C、D、E 继承 B 并且都有非常不同的属性。它们中的每一个都应该是一个带有 A 外键的表。
我得到了我想要的表,但我不知道如何从具有一个属性 IList 的实体 A 映射
HasMany
。 SomeProperty
我想在 ClassMap
中定义 SomeProperty
在 C、D、E 上级联
这显然不起作用,在 ClassMap< ;A>
:
HasMany
HasMany
HasMany
).Cascade.All();
因为我无法复制 B。
示例:
public class Person
{
public virtual IList<Animal> Animals { get; set; }
public void AddAnimal(Animal animal)
{
Animals.Add(animal);
}
}
public abstract class Animal
{
//some common properties
}
public class Cat : Animal
{
//some cat properties
}
public class Horse : Animal
{
//some horse properties
}
在本例中,我希望 ClassMap
通过抽象类 Animal 映射到 Cat 和 Horse。
I have the following domain model to map using ClassMaps/SubclassMaps
A - HasMany -> B (A should be table)
B is abstract in code (and should not be a table)
C,D,E inherits B and all have very different properties. Each of them should be a table with foreign key to A.
I get the tables I want, but I cannot see how to map HasMany
from entity A that has one property IList<B> SomeProperty
I would like to define in ClassMap<A>
that SomeProperty
cascades on C,D,E
This obviously doesn't work, in ClassMap<A>
:
HasMany<C>(x => x.B).Cascade.All();
HasMany<D>(x => x.B).Cascade.All();
HasMany<E>(x => x.B).Cascade.All();
As I cannot duplicate B.
Example:
public class Person
{
public virtual IList<Animal> Animals { get; set; }
public void AddAnimal(Animal animal)
{
Animals.Add(animal);
}
}
public abstract class Animal
{
//some common properties
}
public class Cat : Animal
{
//some cat properties
}
public class Horse : Animal
{
//some horse properties
}
In this case I would like ClassMap<Person>
to map to Cat and Horse over the abstract class Animal.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)