【发布时间】:2010-08-24 10:28:51
【问题描述】:
基本上,我需要为使用父对象数据的查询结果设置一个属性。
使用下面的域模型,我需要使用来自 EntityA 和 EntityB 的数据来设置 EntityB 的 C 属性。
另外,我需要将 EntityB 的 A 属性设置为作为其父级的 EntityA 的实际实例。
查询:
Set EntityB.C = (select * from EntityC where SomeProperty = EntityB.SomeProperty and AnotherProperty = EntityB.A.AnotherProperty);
SomeProperty 和 AnotherProperty 不仅仅是键。
class EntityA
{
public IList<EntityB> B
{
get;
set;
}
}
class EntityB
{
public EntityA A
{
get;
set;
}
public EntityC C
{
get;
set;
}
}
class EntityC
{
...
}
我需要一种方法来为返回的每个实体执行代码(运行查询并分配给属性)。我使用拦截器的 onload 方法接近了,但我正在寻找另一种方法。也许使用结果转换器或投影?
【问题讨论】:
标签: c# nhibernate