Basically, I have a list of reports, and each report belongs to an area. Each user has permissions in each area. I need to list the reports that my user can see, that is, the reports that belongs to areas in which the logged user has at least read permissions.
I'm using linq expression to create a predicate and run through a detachedQuery.
I've been working on this issue for a while, found many suggestions, such as: - LinqKit - https://www.tabsoverspaces.com/233644-playing-with-parameters-limit-on-sql-server-with-entity-framework - Entity Framework Hitting 2100 Parameter Limit
None seem to be my case since I'm not exactly retrieving a list, I'm just running a predicate.
Using "contains" made get to this problem with 2100 parameters because I have more than 3000 areas in my database. What I tried to do first was to divide areas in two lists, the first includes areas that I have permission, the second includes not permitted areas. The smallest list goes to my predicate. This approach worked fine for a while, but now I have more than 4500 areas. Therefore that does not work anymore.
var predicate = PredicateBuilder.Create<Report>();
var areasWithPermission = user.Permissions.Where(v => v.Access != AccessType.NotAllowed).Select(v => v.Area.Id).ToList();
var areasWithoutPermission= user.Permissions.Where(v => v.Access == AccessType.NotAllowed).Select(v => v.Area.Id).ToList();
var predicateSearchPermissions = PredicateBuilder.Create<Report>();
if (areasWithPermission > areasWithoutPermission) {
predicateSearchPermissions = predicateSearchPermissions.OrElse(a => !areasWithoutPermission.Contains(a.Area.Id))
}
else
{
predicateSearchPermissions = predicateSearchPermissions.OrElse(a => areasWithPermission .Contains(a.Area.Id))
}
predicate = predicate.AndAlso(predicateSearchPermissions);
Here is a simple representation of my environment: