简体   繁体   English

相同表的NHibernate映射

[英]Same table NHibernate mapping

How can i go about defining a same table relation mapping (mappingbycode) using Nhibernate 如何使用Nhibernate定义相同的表关系映射(mappingbycode)

for instance let's say I have a class: 例如,假设我有一堂课:

public class Structure{
 public int structureId;
 public string structureName;
 public Structure rootStructure;
}

that references the same class as rootStructure. 引用与rootStructure相同的类。

 mapper.Class<Structure>(m =>
            {
                m.Lazy(true);
                m.Id(u => u.structureId, map => { map.Generator(Generators.Identity); });
                m.Property(c => c.structureName);
                m.? // Same table mapping 
}
 ;

Thanks 谢谢

there is no special mapping for recursive mappings i am aware of. 我知道递归映射没有特殊的映射。 Just map it like you would map a collection of a different class. 就像映射一个不同类的集合一样映射它即可。 In your case this should work (untested though): 在您的情况下,这应该可以工作(尽管尚未试用):

m.OneToOne(c => c.rootStructure, a => a.Lazy(LazyRelation.Proxy))

NHibernate will assume that the foreign key for this relation is stored on column rootStructure of the table associated to that class. NHibernate将假定此关系的外键存储在与该类关联的表的rootStructure列上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM