我想要将NHibernate CreateCriteria转换为NHLambdaExtensions条件,但我收到了错误,我不知道如何修复。
NHibernate标准如下所示:
var departments = DepartmentService
.CreateCriteria()
.CreateAlias( "Goals", "goal" )
.Add( Expression.Eq( "goal.Company.Id", companyId ) )
.Add( Expression.Eq( "goal.Program.Id", programId ) )
.List<Business.Department>();我尝试创建的NHLambdaExtensions标准如下所示:
Business.Goal goalAlias = null;
var departments = DepartmentService
.CreateCriteria()
.CreateAlias<Business.Goal>( g => g.Department, () => goalAlias )
.Add<Business.Goal>( g => g.Company.Id == companyId )
.Add<Business.Goal>( g => g.Program.Id == programId )
.List<Business.Department>();我得到的错误是“无法解析Business.Department的属性部门”。错误显然与"g => g.Department“有关,原始NHibernate查询中没有类似的内容,但没有不接受该表达式的重载。
发布于 2009-09-14 17:58:44
Business.Goal goalAlias = null;
var departments = DepartmentService
.CreateCriteria(typeof(Business.Department)) // need to specify the first criteria as Business.Department
.CreateCriteria<Business.Department>(d => d.Goals, () => goalAlias)
.Add<Business.Goal>( g => g.Company.Id == companyId )
.Add<Business.Goal>( g => g.Program.Id == programId )
.List<Business.Department>();在NHibernate Lambda Extensions (V1.0.0.0) - Documentation中查找“创建与别名关联的条件”
编辑:
实际上,您可以更有效地将其编写为:
// no alias necessary
var departments = DepartmentService
.CreateCriteria<Business.Department>()
.CreateCriteria<Business.Department>(d => d.Goals)
.Add<Business.Goal>( g => g.Company.Id == companyId )
.Add<Business.Goal>( g => g.Program.Id == programId )
.List<Business.Department>();发布于 2009-04-17 21:14:46
我还没有用过NHLambdaExpressions (但它看起来很酷,我很快就会去看看它),所以我只是猜测一下。你能这样做吗:
Business.Goal goalAlias = null;
var departments = DepartmentService
.CreateCriteria()
.CreateCriteria((Business.Department g) => g.Goals, () => goalAlias)
.Add<Business.Goal>( g => g.Company.Id == companyId )
.Add<Business.Goal>( g => g.Program.Id == programId )
.List<Business.Department>();我认为这将在Goals上建立一个新的标准,并通过goalAlias分配一个别名。
https://stackoverflow.com/questions/761672
复制相似问题