开发者

Mapping Generic Classes using NHibernate

开发者 https://www.devze.com 2022-12-12 17:51 出处:网络
I\'m trying to do the following, but it\'s complaining that the \"classes referenced by \'extends\' were not found\". I think I need to having a mapping for each concrete type of Component but I can\'

I'm trying to do the following, but it's complaining that the "classes referenced by 'extends' were not found". I think I need to having a mapping for each concrete type of Component but I can't specify the Attributes.Class twice..

The code is as follows:

[NHibernate.Mapping.Attributes.Class(Table = "Components", Abstract = true,
    NameType = typeof (Component<ContentItem>))]
public abstract class Component<T> : IComponent<T> where T : ContentItem
{
    ...
}

[NHibernate.Mapping.Attributes.JoinedSubclass(Table = "ComponentA", ExtendsType = typeof(Component<ItemA>))]
public class ComponentA : Component<ItemA>
{
    ...
}

[NHibernate.Mapping.Attributes.JoinedSubclass(Table = "ComponentB", ExtendsType = typeof(Component<ItemB>))]
public class ComponentB : Component<ItemB>
{
    ...
}
开发者_开发百科

Where ItemA and ItemB inherit from ContentItem and are all mapped.


You can't map an open generic type like this, i.e. one that has an unspecified type parameter <T>. It just doesn't work.

Ayende discusses this in more detail on his blog.

0

精彩评论

暂无评论...
验证码 换一张
取 消