나는 다음과 같은 계층 개체를 매핑을 시도하고, NHibernate에 3.2 ByCode 구성을 사용 ByCode이 잘 작동계층 엔티티 부모 키
public class BusinessTypeMapper : ClassMapping<BusinessType>
{
public BusinessTypeMapper()
{
Id(x => x.BusinessTypeId, x => x.Type(new GuidType()));
Property(x => x.ParentBusinessTypeId, x => x.Type(new GuidType()));
Property(x => x.BusinessTypeName);
Set(x => x.Children,
cm =>
{
// This works, but there is an ugly string in here
cm.Key(y => y.Column("ParentBusinessTypeId"));
cm.Inverse(true);
cm.OrderBy(bt => bt.BusinessTypeName);
cm.Lazy(CollectionLazy.NoLazy);
},
m => m.OneToMany());
}
}
,하지만 난 차라리 람다를 사용하여 릴레이션의 핵심을 지정하여 리팩토링이 작동하도록 할 수 있습니다. 이것은 다음과 같이 사용할 것 같다 :
public class BusinessTypeMapper : ClassMapping<BusinessType>
{
public BusinessTypeMapper()
{
Id(x => x.BusinessTypeId, x => x.Type(new GuidType()));
Property(x => x.ParentBusinessTypeId, x => x.Type(new GuidType()));
Property(x => x.BusinessTypeName);
Set(x => x.Children,
cm =>
{
// This compiles and runs, but generates some other column
cm.Key(y => y.PropertyRef(bt => bt.ParentBusinessTypeId));
cm.Inverse(true);
cm.OrderBy(bt => bt.BusinessTypeName);
cm.Lazy(CollectionLazy.NoLazy);
},
m => m.OneToMany());
}
}
문제는이 이미 구성 ParentBusinessTypeId
을 무시하고, businesstype_key
라는 열을 생성하는 NHibernate에 원인이 있다는 것입니다. Hibernate가 문자열이 아닌 관계를 지정하기 위해 람다 (lambda)를 사용하도록하는 방법이 있습니까?
'public virtual BusinessType Parent {get; 세트; }'? – Firo
내 질문에 그 문제를 해결하는 데 도움이 될까요? 나는 부모에게서 자식까지 탐색 할 필요가 없으므로 필요 없다고 생각했다. –