我需要在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))
但是这会选择全部(选择),我只想要Command对象(选择sc。)。 如果我尝试向查询添加投影,请执行以下操作:
queryOverRole.Select(x=>x);
它抛出了这个异常:
System.Exception was caught Message=Could not determine member
来自x Source = NHibernate
堆栈跟踪: 在NHibernate.Impl.ExpressionProcessor.FindMemberExpression(表达式 表达)in d:\ CSHARP \ NH \的nhibernate \ SRC \ NHibernate的\默认地将Impl \ ExpressionProcessor.cs:线 189 在NHibernate.Criterion.QueryOver2.Select(Expression
1 [] 预测) d:\ CSHARP \ NH \的nhibernate \ SRC \ NHibernate的\判据\ QueryOver.cs:线 363 at Novatec.Persistence.Repositories.Implementations.UserRepository.GetAllowedUserCommands(Int32 userId)in C:\项目\ EGrad \主\源\ Novatec.E-梯度\源\ Novatec.Persistence \库\实现\ UserRepository.cs:线 140 at Novatec.Administracija.Services.Security.SecurityManager.AuthorizeUserAction(Int32 userId,String commandId)in C:\项目\ EGrad \ MAIN \来源\ Novatec.E格勒\来源\ Novatec.Administracija.Services \安全\ SecurityManager.cs:行 48 在Novatec.Framework.Infrastructure.Services.ServiceBase.ExecuteCommand(Int32 userId,String appId,ICommand 命令)in C:\项目\ EGrad \ MAIN \来源\ Novatec.E格勒\来源\ Novatec.Framework.Infrastructure \ SERVICES \ ServiceBase.cs:行 94 InnerException:
答案 0 :(得分:1)
试试这个....您需要指定要选择的别名。 queryOverRole.Select(result =&gt; cmdAlias);