dynamic-linq

ASP.NET MVC Authorization based on role membership or data relation (ownership)

余生长醉 提交于 2019-12-06 13:32:26
问题 I'd like to extend the AuthorizeAttribute in ASP.NET MVC so that it supports the concept of a user's authorization being based on their role membership OR "ownership" of the data in question. I'm using LINQ2SQL for data access. There is a similar question at asp.net mvc authorization using roles. What I'm thinking is adding EntityProperty, UserProperty, RouteParameter, and JoinTableType parameters to my extended AuthorizeAttribute class. The first two would be the names of the properties in

System.Linq.Dynamic.DynamicExpression parsing expressions with methods

十年热恋 提交于 2019-12-06 11:26:10
问题 I need to build a system where I have a number of expressions that are stored in a file. These expressions would be read into the program, compiled into linq expressions and evaluated as functions on a number of objects. However, these expressions would contain references to some functions in the code (i.e. they would not be made of just basic C# operators). I'm trying to use DynamicExpression from System.Linq.Dynamic and it almost works, except that my functions from the code are not

Get an Entity Object with its child Entity with a condition (using Dynamic Linq)

亡梦爱人 提交于 2019-12-06 10:24:45
This question is continuation of Getting Count() property in Dynamic Lambda Expression I had asked if we can put Count() Method in dynamic lambda expression. I could do it using Dynamic Expression API . Answer provided by - xmojmr But recently I had to implement a Dynamic Lambda Expression to get result with its child entity with filtered data. Details : I have a parent entity with its child entity linked. Now when I get data from parent entity, it returns a collection of data with its child data too. as per my previous requirement I had to count all child record returned with respect to each

Execution-Deferred IQueryable<T> from Dynamic Linq?

喜欢而已 提交于 2019-12-05 01:58:34
I am using Dynamic Linq to perform some queries (sorry but it's my only option). As a result, I am getting an IQueryable instead of an IQueryable<T> . In my case, I want an IQueryable<Thing> where Thing is a concrete type. My query is as such: public IQueryable<Thing> Foo(MyContext db) { var rootQuery = db.People.Where(x => x.City != null && x.State != null); var groupedQuery = rootQuery.GroupBy("new ( it.City, it.State )", "it", new []{"City", "State"}); var finalLogicalQuery = groupedQuery.Select("new ( Count() as TotalNumber, Key.City as City, Key.State as State )"); var

ASP.NET MVC Authorization based on role membership or data relation (ownership)

僤鯓⒐⒋嵵緔 提交于 2019-12-04 18:18:39
I'd like to extend the AuthorizeAttribute in ASP.NET MVC so that it supports the concept of a user's authorization being based on their role membership OR "ownership" of the data in question. I'm using LINQ2SQL for data access. There is a similar question at asp.net mvc authorization using roles . What I'm thinking is adding EntityProperty, UserProperty, RouteParameter, and JoinTableType parameters to my extended AuthorizeAttribute class. The first two would be the names of the properties in the join table to check. The RouteParameter would be the name of the route parameter to extract for the

Dynamic Or Clause Linq

血红的双手。 提交于 2019-12-04 11:30:24
问题 Today we currently have a statement like this: var Query = (from dp in db.Patients select dp); var UserID = User.Identity.GetUserId(); if (User.IsInRole("Administrator")) { Query = Query.Where(x => x.AdministratorID == UserID); } if (User.IsInRole("Counselor")) { Query = Query.Where(x => x.CounselorID == UserID); } if (User.IsInRole("Physician")) { Query = Query.Where(x => x.PhysicianID == UserID); } The problem is we have Users that can have multiple roles. If a User is both an Counselor and

How to use Dynamic LINQ (System.Linq.Dynamic) for LIKE operation?

北城以北 提交于 2019-12-04 08:26:40
问题 Can any body tell me how can I use a LIKE operator using System.Linq.Dynamic? I need to add more than one LIKE expression in my dynamic where query /* var query = db.Customers. Where("CityName Like @0 or CityName Like @1", "London", "USA") */ var query = db.Customers. Where("CityName Like @0 or CityName Like @1%", "London", "USA") thanks heaps 回答1: Try using simply "CityName.Contains(@1)" this will convert to the proper lambda since its a method invocation on an accessible type. something

How can I sort a list based on a user's selections in ASP.NET MVC?

折月煮酒 提交于 2019-12-04 08:00:50
I have a list of customers that can be sorted by anywhere from 1 to 6 fields based on a user's selection. The sort fields can be in any order. If I know the fields and the sequence ahead of time, sorting is easy: customers = customers .OrderBy(c => c.LastName) .ThenBy(c => c.City) .ThenBy(c => c.Age).ToList(); How would I pass in the sort fields at runtime? Is there a way to do something like this? string sortField1 = "State"; string sortField2 = "City"; string sortField3 = "Type"; customers = customers .OrderBy(c => c.sortField1) .ThenBy(c => c.sortField2) .ThenBy(c => c.sortField3).ToList();

Invoking Regex.IsMatch() inside a dynamic linq query

孤人 提交于 2019-12-04 06:28:02
问题 I'm trying to invoke the Regex.IsMatch() and evaluate the returned result inside a dynamic linq query. This is what I tried: public static LambdaExpression Parse(SearchQuery query) { string compilableExpression = "Regex.IsMatch(Category.ToLower(), \"\\bSomeCat\\b\", RegexOptions.Compiled) == true"; ParameterExpression parameter1 = System.Linq.Expressions.Expression.Parameter(typeof(EventListItem)); ParameterExpression parameter2 = System.Linq.Expressions.Expression.Parameter(typeof(Regex));

Exception using OrElse and AndAlso expression methods

廉价感情. 提交于 2019-12-04 00:11:22
问题 I am trying to build an expression tree programmatically. I have in my input, a list of condition classes which have the following form: public class Filter { public string field { get; set; } public string operator { get; set; } public string value { get; set; } } When I build the Expression object I create an Expression for every condition in the following way foreach ( Filter sf in rules ) { Expression ex = sf.ToExpression( query ); if ( mainExpression == null ) { mainExpression = ex; }