本文介绍了使用NHibernate映射的一般类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做到以下几点,但它抱怨被引用的类'延伸',未发现。我想我需要有针对每个具体类型部件的映射,但我不能指定Attributes.Class两倍。

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..

在code是如下:

[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>
{
    ...
}

在哪里意达和ItemB从ContentItem继承和都被映射。

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

推荐答案

您不能映射一个开放的泛型类型这样的,即一个有一个未指定类型参数&LT; T&GT; 。这是行不通的。

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讨论了这个在更详细的他博客

Ayende discusses this in more detail on his blog.

这篇关于使用NHibernate映射的一般类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 12:07