Hi,

I am trying to convert the Rhino Security ApplyPermissionsToQuery to
use Linq:

        private ICriterion GetPermissionQueryInternal(IUser user,
string operation, string securityKeyProperty)
        {
            UsersGroup[] groups =
authorizationEditingService.GetAssociatedUsersGroupFor(user);
            string[] operationNames =
Strings.GetHierarchicalOperationNames(operation);
            DetachedCriteria criteria =
DetachedCriteria.For<Permission>("permission")
                .CreateAlias("Operation", "op")
                .CreateAlias("EntitiesGroup", "entityGroup",
JoinType.LeftOuterJoin)
                .CreateAlias("entityGroup.Entities", "entityKey",
JoinType.LeftOuterJoin)
                .SetProjection(Projections.Property("Allow"))
                .Add(Expression.In("op.Name", operationNames))
                .Add(Expression.Eq("User", user) ||
Expression.In("UsersGroup", groups))
                .Add(
 
Property.ForName(securityKeyProperty).EqProperty("permission.EntitySecurityKey")
||
 
Property.ForName(securityKeyProperty).EqProperty("entityKey.EntitySecurityKey")
||
                (
                    Expression.IsNull("permission.EntitySecurityKey")
&&
                    Expression.IsNull("permission.EntitiesGroup")
                )
                )
                .SetMaxResults(1)
                .AddOrder(Order.Desc("Level"))
                .AddOrder(Order.Asc("Allow"));
            return Subqueries.Eq(true, criteria);
        }


This generates the following example query:

SELECT
this_.CatalogueId as Catalogu1_19_0_, this_.Name as Name19_0_
FROM Catalogue this_
WHERE @p0 = (

SELECT this_0_.Allow as y0_
FROM Permissions this_0_ inner join Operations op1_ on
this_0_.OperationId=op1_.OperationId
left outer join EntitiesGroups entitygrou2_ on
this_0_.EntitiesGroupId=entitygrou2_.EntitiesGroupId
left outer join EntityReferencesToEntitiesGroups entities7_ on
entitygrou2_.EntitiesGroupId=entities7_.GroupId
left outer join EntityReferences entitykey3_ on
entities7_.EntityReferenceId=entitykey3_.EntityReferenceId
WHERE op1_.Name in (@p1, @p2) and (this_0_.UserId = @p3 or 1=0)
and ((this_.CatalogueId = this_0_.EntitySecurityKey or
this_.CatalogueId = entitykey3_.EntitySecurityKey) or
(this_0_.EntitySecurityKey is null
and this_0_.EntitiesGroupId is null))
ORDER BY this_0_.Level desc, this_0_.Allow asc limit 1)



Now, taking a slightly simplified version to start with I am
struggling with the sub-query:

This generates the same SQL for the subquery part (ignoring the extra
where clauses for now) :

            var items = IoC.Resolve<IRepository<Permission>>().Query()
                .Where(p => p.EntitySecurityKey == catA.Id)
                .OrderByDescending(p => p.Level)
                .OrderBy(p => p.Allow)
                .Select(p => p.Allow)
                .Take(1);


But I am unable to work out how to achieve the equivalent true =
(subquery...) in Linq, similar to:

            var cats = from catalogue in catalogueRepo.Query()
                       where true == (
 
IoC.Resolve<IRepository<Permission>>().Query()
                                .Where(p => p.EntitySecurityKey ==
catA.Id)
                                .OrderByDescending(p => p.Level)
                                .OrderBy(p => p.Allow)
                                .Select(p => p.Allow)
                                .Take(1)

                       )
                       select catalogue
            ;

(the where true == doesn't work obviously). Any ideas on how to
achieve the same sort of subquery or any alternative suggestions?




-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to