当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - NHibernate mapping of generic class

问题描述:

I have a problem with mapping of generic class.

So I have a class Spec:

namespace BackOffice.Core.Domains

{

public abstract class Spec: BaseDomain

{

public virtual string Name { get; set; }

public virtual TypeSpecValue TypeSpecValue { get; set; }

}

public enum TypeSpecValue

{

StringType = 0,

DecimalType = 1,

Booltype = 2

};

}

For this class i have mapping and it work.

Then I have generic class SpecValue:

namespace BackOffice.Core.Domains

{

public class SpecValue<T>: BaseDomain where T : Spec

{

public virtual T Spec { get; set; }

public virtual string StrValue { get; set; }

public virtual decimal NumValue { get; set; }

public virtual bool BoolValue { get; set; }

}

}

So I need to map this class. I tried this way after reading this article

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"

assembly="Transport.Core"

namespace="BackOffice.Core.Domains">

<class name="SpecValue`1[BackOffice.Core.Domains.Spec], Transport.Core" table="spec_value">

<id name="Id" unsaved-value="0" type="int">

<column name="id" not-null="true"/>

<generator class="native"/>

</id>

<many-to-one name="Spec" class="BackOffice.Core.Domains.Spec,Transport.Core" column="spec_id" fetch="join"/>

<property name="StrValue" type="String">

<column name="str_value" />

</property>

<property name="NumValue" type="Decimal">

<column name="num_value" />

</property>

<property name="BoolValue" type="YesNo">

<column name="bool_value" />

</property>

<many-to-one name="Model" class="BaseModel,Transport.Core" column="model_id" cascade="none" />

</class>

</hibernate-mapping>

What did I wrong? This mapping doesn't work and i don't understand why. I already checked names of assembly and namespace and it's ok. Any suggestions? I will be glad to any help in this question.

网友答案:

Make sure that your mapping file is set as an "Embedded Resource" in the properties. Otherwise the file is not included in the DLL that is built, and NHibernate cannot find it then.

分享给朋友:
您可能感兴趣的文章:
随机阅读: