2

我需要在 nhibernate QueryOver 中执行此操作:

select distinct sc.* from [Security].[Commands] sc
inner join [Security].[SystemSubjects] ss on ss.Id = sc.Id
left outer join [Security].[SystemSubjectRoles] ssr on ssr.SystemSubjectId = ss.Id
left outer join [Security].[Roles] sr on sr.Id = ssr.RoleId
left outer join [Security].[UserRoles] ur on ur.IdRole = sr.Id 
left outer join [Security].[User] su2 on su2.Id = ur.IdUser
left outer join [Security].SystemSubjectUsers ssu on ssu.SystemSubjectId = ss.Id
left outer join [Security].[User] su on su.Id = ssu.UserId
where (su2.Id = 1 or su.Id = 1)

到目前为止,我已经这样做了:

var queryOverRoles = QueryOver.Of<Command>(() => cmdAlias)
            .JoinAlias(() => cmdAlias.SystemSubjectRoles, () => ssRoleAlias, JoinType.LeftOuterJoin)
            .JoinAlias(() => ssRoleAlias.Role, () => roleAlias, JoinType.LeftOuterJoin)
            .JoinAlias(() => roleAlias.Users, () => userAlias, JoinType.LeftOuterJoin)
            .JoinAlias(() => cmdAlias.SystemSubjectUsers, () => ssUserAlias, JoinType.LeftOuterJoin)
            .JoinAlias(() => ssUserAlias.User, () => userAlias2, JoinType.LeftOuterJoin)
            .TransformUsing(Transformers.DistinctRootEntity)
            .Where(() => ssRoleAlias.SecurityPermission == SecurityPermission.Allow)
            .And(() => (userAlias.Id == userId || userAlias2.Id == userId))

但这会选择所有(Select ),我只想要 Command 对象(select sc.)。如果我尝试像这样向查询添加投影:

queryOverRole.Select(x=>x);

它抛出这个异常:

System.Exception was caught   Message=Could not determine member

来自 x Source=NHibernate
StackTrace: 在 NHibernate.Impl.ExpressionProcessor.FindMemberExpression(Expression expression) in d:\CSharp\NH\nhibernate\src\NHibernate\Impl\ExpressionProcessor.cs: NHibernate.Criterion.QueryOver 的第 189 行2.Select(Expression1[] 投影)在 d:\CSharp\NH\nhibernate\src\NHibernate\Criterion\QueryOver.cs:C:\Projects\EGrad 中 Novatec.Persistence.Repositories.Implementations.UserRepository.GetAllowedUserCommands(Int32 userId) 的第 363 行\Main\Source\Novatec.E-Grad\Source\Novatec.Persistence\Repositories\Implementations\UserRepository.cs:C:\ 中 Novatec.Administracija.Services.Security.SecurityManager.AuthorizeUserAction(Int32 userId, String commandId) 的第 140 行Projects\EGrad\Main\Source\Novatec.E-Grad\Source\Novatec.Administracija.Services\Security\SecurityManager.cs:Novatec.Framework.Infrastructure.Services.ServiceBase.ExecuteCommand 的第 48 行(Int32 userId,String appId,ICommand命令)在 C:\Projects\EGrad\Main\Source\Novatec.E-Grad\Source\Novatec.Framework.Infrastructure\Services\ServiceBase.cs:第 94 行内部异常:

4

1 回答 1

1

试试这个....您需要指定要选择的别名。queryOverRole.Select(result => cmdAlias);

于 2011-04-17T12:16:36.263 回答