NHibernate的 - 无法找到一个getter财产 [英] Nhibernate - Could not find a getter for property
问题描述
我试图建立MusicStore NHibernate的端口,我碰到这个错误:
I'm trying to build the MusicStore Nhibernate port, and I've run into this error:
找不到类吸气财产订单信息 MvcMusicStore.Models.OrderDetail
Could not find a getter for property 'OrderInfo' in class 'MvcMusicStore.Models.OrderDetail'
与下面的内部异常:
NHibernate.PropertyNotFoundException:找不到getter方法 在类属性订单信息MvcMusicStore.Models.OrderDetail
NHibernate.PropertyNotFoundException: Could not find a getter for property 'OrderInfo' in class 'MvcMusicStore.Models.OrderDetail'
,而使用下面的映射的OrderDetail:
while using the following mapping for OrderDetail:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="MvcMusicStore" namespace="MvcMusicStore.Models">
<class name="OrderDetail">
<id name="Id">
<generator class="hilo" />
</id>
<many-to-one name="OrderInfo" column="OrderInfoId" />
<property name="Quantity" />
<property name="UnitPrice" />
<many-to-one name="Album" column="AlbumId" />
</class>
</hibernate-mapping>
和C#类定义:
And the C# class definition:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcMusicStore.Models
{
public class OrderDetail : Entity
{
public virtual OrderInfo Order { get; set; }
public virtual Album Album { get; set; }
public virtual int Quantity { get; set; }
public virtual decimal UnitPrice { get; set; }
}
}
映射为订单信息类如下:
The mapping for the OrderInfo class is the following:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="MvcMusicStore" namespace="MvcMusicStore.Models">
<class name="OrderInfo">
<id name="Id">
<generator class="hilo" />
</id>
<property name="OrderDate" />
<property name="Username" />
<property name="FirstName" />
<property name="LastName" />
<property name="Address" />
<property name="City" />
<property name="State" />
<property name="PostalCode" />
<property name="Country" />
<property name="Phone" />
<property name="Email" />
<property name="Total" />
<set name="OrderDetails">
<key column="OrderInfoId" />
<one-to-many class="OrderDetail" />
</set>
</class>
</hibernate-mapping>
和它下面的C#类定义:
and it has the following C# class definition:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcMusicStore.Models
{
public class OrderInfo : Entity
{
public virtual DateTime OrderDate { get; set; }
public virtual string Username { get; set; }
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual string Address { get; set; }
public virtual string City { get; set; }
public virtual string State { get; set; }
public virtual string PostalCode { get; set; }
public virtual string Country { get; set; }
public virtual string Phone { get; set; }
public virtual string Email { get; set; }
public virtual string Total { get; set; }
public virtual ICollection<OrderDetail> OrderDetails { get; set; }
}
}
实体类是增加了一个的Guid ID属性的抽象类。我究竟做错了什么?老实说,我看不出有任何的故障与我的映射。
The Entity class is an abstract class which adds an Guid ID property. What am I doing wrong? I honestly can't see any faults with my mappings.
推荐答案
在映射文件你说:
<many-to-one name="OrderInfo" column="OrderInfoId" />
和你必须说:
<many-to-one name="Order" column="OrderInfoId" />
这篇关于NHibernate的 - 无法找到一个getter财产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!