NHibernate QueryOver [英] NHibernate QueryOver
问题描述
我有对象C,它拥有一个对象L的列表,对象C也拥有一个对象C引用R类。
从对象LI中找到对象R。
我试图做这个,但是我只使用这个代码得到null:
L已经是一个函数接收的实例对象。
var t = SessionController.CurrentSession.QueryOver< C>()
.Where(c => c。 (c => cR)
.Select(c => cR).SingleOrDefault();
不知道我在做什么错在这里将不胜感激。
谢谢
问题是您的SingleOrDefault调用正在返回类C的一个实例,我猜测而不是类C的实例,它具有关联类R的Id。您将希望如下修改您的查询:
(c => c.Id == L.C_Id)
.JoinQueryOver R(c => cR)
.Select(c => cR).SingleOrDefault< R>();
请注意SingleOrDefault调用的显式类型。
I've searched around but not found what I am doing wrong here.
I have object C which holds a list of object L, object C also holds a reference to class R.
From object L I want to find object R.
I'm trying to do this but I only get null using this code:
L is already an instanced object a function receives.
var t = SessionController.CurrentSession.QueryOver<C>()
.Where(c => c.Id == L.C_Id)
.JoinQueryOver<R>(c => c.R)
.Select(c => c.R).SingleOrDefault();
Any idea what I'm doing wrong here would be appreciated. Thanks
The problem is your SingleOrDefault call is returning an instance of class C and I'm guessing there is not instance of class C that has the Id of the associated class R. You'll want to modify your query as follows:
var t = SessionController.CurrentSession.QueryOver<C>()
.Where(c => c.Id == L.C_Id)
.JoinQueryOver<R>(c => c.R)
.Select(c => c.R).SingleOrDefault<R>();
Note the explicit typing of the SingleOrDefault call.
这篇关于NHibernate QueryOver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!