如何将继承与返回的其他继承的属性映射?
我有抽象类 Vehicle 和两个派生自的类:Car 和 ForkLift。
public abstract class Vehicle
{
public EngineBase Engine { get; set; }
}
public class Car : Vehicle
{
public GasEngine Engine { get; set; }
}
public class ForkLift : Vehicle
{
public ElectricEngine Engine { get; set; }
}
和引擎类:
public abstract class EngineBase
{
}
public class GasEngine : EngineBase
{
}
public class ElectricEngine : EngineBase
{
}
引擎通过“每个类层次结构的表”进行映射。对于车辆,我想使用相同的模式。
如何映射 Engine 类并使用该 Engine 属性派生?
如何使用延迟加载来做到这一点?
I have abstract class Vehicle and two classes that derive from: Car and ForkLift.
public abstract class Vehicle
{
public EngineBase Engine { get; set; }
}
public class Car : Vehicle
{
public GasEngine Engine { get; set; }
}
public class ForkLift : Vehicle
{
public ElectricEngine Engine { get; set; }
}
and Engine clasess:
public abstract class EngineBase
{
}
public class GasEngine : EngineBase
{
}
public class ElectricEngine : EngineBase
{
}
Engines are mapped with "table per class hierarchy". With Vehicles I want to use the same pattern.
How to map Engine class and derived with that Engine property?
How to do it with lazy-loading?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该代码无法编译,这使得您不可能映射它。
That code does not compile, which makes it improbable that you can map it.
在 Vehicle 中使用受保护的字段并使用访问策略映射它:
在 Fluent NHibernate 中,这将被映射:
然后扩展 Vehicle 的类可以根据需要对其进行转换:
Use a protected field in Vehicle and map it with an access strategy:
In Fluent NHibernate this would be mapped:
Then the classes that extend Vehicle can cast it as needed: