我在NH#中使用NHibernate,在编译时它给了我这个错误:
{"Could not find a getter for property 'idOrder' in class 'FrancosPoS.DBMapping.ordPsf'"}
我发现了这个问题,但我无法理解如何使用它: Nhibernate - Could not find a getter for property
这是我的映射类:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="FrancosPoS" namespace="FrancosPoS.DBMapping" xmlns="urn:nhibernate-mapping-2.2">
<class name="ordPsf" table="ord_psf" lazy="true" >
<id name="idOrdPastaF">
<generator class="identity" />
<!--<column name="idOrdPastaF" sql-type="int(11)" not-null="true" />-->
</id>
<many-to-one insert="false" update="false" lazy="false" name="idOrder">
<column name="idOrder" sql-type="int(11)" not-null="true" />
</many-to-one>
<property name="idOrder">
<column name="idOrder" sql-type="int(11)" not-null="true" />
</property>
<many-to-one insert="false" update="false" lazy="false" name="idPastaF">
<column name="idPastaF" sql-type="int(11)" not-null="true" />
</many-to-one>
<property name="idPastaF">
<column name="idPastaF" sql-type="int(11)" not-null="true" />
</property>
.
.
.
<property name="obs">
<column name="obs" sql-type="varchar(50)" not-null="false" />
</property>
<property name="price">
<column name="price" sql-type="decimal(8,4)" not-null="true" />
</property>
</class>
</hibernate-mapping>
这是我的cs课程:
namespace FrancosPoS.DBMapping {
public partial class ordPsf {
public ordPsf() { }
public virtual int idOrdPastaF { get; set; }
public virtual order order { get; set; }
public virtual pastaFeast pastaFeast { get; set; }
public virtual salad salad { get; set; }
public virtual onTheSide onTheSide { get; set; }
public virtual string obs { get; set; }
public virtual string price { get; set; }
}
}
我的猜测是我做的映射错了。由于显而易见的原因,我不想让idOrder获取/设置因为我需要使用该对象。 (此外,我猜测修复此错误后,其他ID会发生同样的错误)
答案 0 :(得分:0)
我不知道你在这里尝试什么。根据映射,您的班级必须是:
public partial class ordPsf {
public ordPsf() { }
public virtual int idOrder { get; set; }
public virtual int idPastaF{ get; set; }
.....
public virtual string obs { get; set; }
public virtual decimal price { get; set; }
}
答案 1 :(得分:0)
如果您不想使用具有公共访问者的属性,可以map to a private field:
<column ... access="field" .../>
答案 2 :(得分:0)
我发现问题出在&lt;物业&gt;与&lt;冲突“多对一&gt;关系:
<property name="idOrder">
<column name="idOrder" sql-type="int(11)" not-null="true" />
</property>
我们不需要这个,因为多对一将负责订单对象(和id)。
通过查看如何映射多对一关系找到:http://ajlopez.wordpress.com/2011/05/19/nhibernate-3-part-6-one-to-many-with-many-to-one/