我想使用nHibernate Future从数据库中检索一个具有整个组织结构的客户端。
我试过这样的事情:
public DBClient GetOrganizationStructure(long clientOid)
{
var f0 = Query().Fetch(x => x.RegisteredAddress).Fetch(x => x.BillingAddress).Fetch(x => x.RegisteredOffices).Where(x=>x.Oid == clientOid).ToFuture();
var f1 = Session.Query<DBRegisteredOffice>().Fetch(x => x.DeliveryAddress).Where(x => x.Client.Oid == clientOid).ToFuture();
var f2 = Session.Query<DBDepartment>().Fetch(x => x.Workplaces).Where(x => x.RegisteredOffice.Client.Oid == clientOid).ToFuture();
var f3 = Session.Query<DBWorkplace>().Fetch(x => x.Expertise).Where(x => x.RegisteredOffice.Client.Oid == clientOid || x.Department.RegisteredOffice.Client.Oid == clientOid).ToFuture();
var v = f0.ToList();
return v.First();
}
但是当我处理检索到的数据时,会完成对数据库的另一次调用。
我很确定我在使用ToFuture()时遗漏了一些东西。你能指点我一些相关的网页并帮我解决这个ToFuture样本吗?
由于
编辑:如果使用QueryOver,您可以使用以下
更详细:
DBRegisteredOffice registeredOfficeAlias = null;
DBClient clientAlias = null;
DBDepartment departmentAlias = null;
DBWorkplace workplaceAlias = null;
var query = Session.QueryOver(() => clientAlias)
.Fetch(x => x.RegisteredAddress).Eager
.Fetch(x => x.BillingAddress).Eager
.Left.JoinAlias(x => x.RegisteredOffices, () => registeredOfficeAlias)
.Where(x => x.Oid == clientOid)
.Future();
Session.QueryOver(() => registeredOfficeAlias)
.Fetch(x => x.DeliveryAddress).Eager
.Where(x => x.Client.Oid == clientOid)
.Future();
Session.QueryOver(() => registeredOfficeAlias)
.Left.JoinAlias(x => x.Departments, () => departmentAlias)
.Where(x => x.Client.Oid == clientOid)
.Future();
Session.QueryOver(() => registeredOfficeAlias)
.Left.JoinAlias(x => x.Workplaces, () => workplaceAlias)
.Where(x => x.Client.Oid == clientOid)
.Future();
Session.QueryOver(() => departmentAlias)
.Fetch(x => x.Workplaces).Eager
.JoinQueryOver(x => x.RegisteredOffice).Where(x => x.Client.Oid == clientOid)
.Future();
Session.QueryOver(() => workplaceAlias)
.JoinQueryOver(x => x.RegisteredOffice).Where(x => x.Client.Oid == clientOid)
.Future();
return query.First();
少详细:
DBRegisteredOffice registeredOfficeAlias = null;
DBClient clientAlias = null;
DBDepartment departmentAlias = null;
var query = Session.QueryOver(() => clientAlias)
.Fetch(x => x.RegisteredAddress).Eager
.Fetch(x => x.BillingAddress).Eager
.Left.JoinAlias(x => x.RegisteredOffices, () => registeredOfficeAlias)
.Where(x => x.Oid == clientOid)
.Future();
Session.QueryOver(() => registeredOfficeAlias)
.Fetch(x => x.DeliveryAddress).Eager
.Fetch(x => x.Workplaces).Eager
.Where(x => x.Client.Oid == clientOid)
.Future();
Session.QueryOver(() => registeredOfficeAlias)
.Left.JoinAlias(x => x.Departments, () => departmentAlias)
.Where(x => x.Client.Oid == clientOid)
.Future();
Session.QueryOver(() => departmentAlias)
.Fetch(x => x.Workplaces).Eager
.JoinQueryOver(x => x.RegisteredOffice).Where(x => x.Client.Oid == clientOid)
.Future();
return query.First();