我想将 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 查询中没有任何类似的内容,但没有不采用该表达式的重载。