使用NHibernate映射通用类
我正在尝试执行以下操作,但它抱怨“未找到’extends’引用的类”。 我想我需要为每个具体类型的Component都有一个映射,但我不能指定Attributes.Class两次..
代码如下:
[NHibernate.Mapping.Attributes.Class(Table = "Components", Abstract = true, NameType = typeof (Component))] public abstract class Component : IComponent where T : ContentItem { ... } [NHibernate.Mapping.Attributes.JoinedSubclass(Table = "ComponentA", ExtendsType = typeof(Component))] public class ComponentA : Component { ... } [NHibernate.Mapping.Attributes.JoinedSubclass(Table = "ComponentB", ExtendsType = typeof(Component))] public class ComponentB : Component { ... }
其中ItemA和ItemB从ContentIteminheritance并全部映射。
您不能映射这样的开放generics类型,即具有未指定类型参数
类型。 它只是不起作用。
Ayende 在他的博客上更详细地讨论了这一点。