我有這樣如何使用Fluent NHibernate映射包含與父類型相同類型的實體的列表?
public class Person
{
public virtual int Pkey { get; set; }
public virtual string Name { get; set; }
public List<Person> Friends{ get; set; }
}
和其表信息的實體就是這樣
create table Person
(
PKey int not null IDENTITY,
Name varchar (20),
primary key (PKey)
)
得到朋友的名單,我保持這樣的
Create table Friends
(
PKey int not null IDENTITY,
PersonFKey int not null Foreign key references Person(PKey),
FriendFKey int not null Foreign key references Person(PKey)
)
現在另一個表當我做如下映射,我得到一些錯誤(因爲映射問題)
public class PersonMap : ClassMap<Person>
{
public PersonMap()
{
Id(x => x.Pkey);
Map(x => x.Name);
HasManyToMany(x => x.Friends).Cascade.All().Table("Friends").ParentKeyColumn("PersonFKey");
}
}
拋出異常是,
FluentConfigurationException: "An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail."
隨着內部異常,
InvalidProxyTypeException: The following types may not be used as proxies:
FluentNhibernateLearning.Entities.Person: method get_Friends should be 'public/protected virtual' or 'protected internal virtual'
FluentNhibernateLearning.Entities.Person: method set_Friends should be 'public/protected virtual' or 'protected internal virtual'
誰能幫我指點,我缺少的是什麼?
任何原因,你沒不要嘗試做例外指示,只是改爲「公共虛擬列表朋友{get;組; }'? –