У меня есть объект, как этотКак сопоставить список, содержащий объекты того же типа, что и родительского типа, с помощью 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'
Может кто-нибудь помочь мне, указывая, что мне не хватает?
Любой причиной вы Бесполезная Не пытайтесь сделать это как указано исключение и просто измените на 'public virtual List Друзья {get; задавать; } '? –