我是 Nhibernate 的新手。希望我能在这里找到答案。这是我的课:
public class PaymentAudit : EntityBase<int>, IAggregateRoot
{
public PaymentAudit() { }
public System.Guid PaymentStateId { get; set; }
public System.DateTime DateStamp { get; set; }
public Payment Trn { get; set; }
public PaymentSaga PaymentSaga { get; set; }
public ProcessState ProcessState { get; set; }
public PublishState PublishState { get; set; }
public System.Nullable<short> ChgCount { get; set; }
public string UserName { get; set; }
protected override void Validate()
{
}
}
这是我的映射:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Praweda.Interface.Framework.Model.Payment"
assembly="Praweda.Interface.Framework.Model">
<class name="PaymentAudit" table="PaymentAudit" lazy="false" >
<composite-id>
<key-property name="PaymentStateId" column="PaymentStateId" />
<key-property name="DateStamp" column="DateStamp" />
<key-property name="ProcessState" column="ProcessState" />
</composite-id>
<id name="PaymentState">
<generator class="identity" />
<column name="PaymentStateId" sql-type="uniqueidentifier" not-null="true" />
</id>
<id name="ProcessState">
<generator class="identity" />
<column name="ProcessState" sql-type="varchar" not-null="true" />
</id>
<id name="DateStamp">
<generator class="identity" />
<column name="DateStamp" sql-type="datetime" not-null="true" />
</id>
<many-to-one insert="false" update="false" lazy="false" name="PaymentStateId">
<column name="PaymentStateId" sql-type="uniqueidentifier" not-null="true" />
</many-to-one>
<property name="PaymentStateId">
<column name="PaymentStateId" sql-type="uniqueidentifier" not-null="true" />
</property>
<many-to-one insert="false" update="false" lazy="false" name="ProcessState">
<column name="ProcessState" sql-type="varchar" not-null="true" />
</many-to-one>
<property name="ProcessState">
<column name="ProcessState" sql-type="varchar" not-null="true" />
</property>
<many-to-one insert="false" update="false" lazy="false" name="PublishState">
<column name="PublishState" sql-type="varchar" not-null="false" />
</many-to-one>
<property name="PublishState">
<column name="PublishState" sql-type="varchar" not-null="false" />
</property>
<many-to-one insert="false" update="false" lazy="false" name="Trn">
<column name="Trn" sql-type="varchar" not-null="false" />
</many-to-one>
<property name="Trn">
<column name="Trn" sql-type="varchar" not-null="false" />
</property>
<property name="ChgCount">
<column name="ChgCount" sql-type="smallint" not-null="false" />
</property>
<property name="UserName">
<column name="UserName" sql-type="nvarchar" not-null="false" />
</property>
</class>
</hibernate-mapping>
当我尝试在会话工厂中添加存储库程序集时,这是代码
Configuration config = new Configuration();
config.AddAssembly("MyProject.Nhibernate.Repository");
log4net.Config.XmlConfigurator.Configure();
config.Configure();
_sessionFactory = config.BuildSessionFactory();
给我错误:命名空间“urn:nhibernate-mapping-2.2”中的元素“类”在命名空间“urn:nhibernate-mapping-2.2”中有无效的子元素“id”。
谢谢!