linq-expressions

How to convert CIL to a LINQ Expression Tree [closed]

南楼画角 提交于 2019-12-05 01:19:36
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . Has any work been done on the direct conversion of CIL to LINQ expression trees? This would include class libraries, blogs, books, academic papers, etc. What are the known mismatches between CIL and LINQ

Generic expression abstraction issue

纵然是瞬间 提交于 2019-12-04 17:25:26
I have the following method SetMapping() which is used to define some mapping setting using expressions. public class AggregateMap<TDataEntity> { protected Expression<Func<IUpdateConfiguration<TDataEntity>, object>> graphMapping; protected void SetMapping(Expression<Func<IUpdateConfiguration<TDataEntity>, object>> mapping) { graphMapping = mapping; } } Example calling code: SetMapping(map => map.OwnedCollection(root => root.ChildEntities)); The above works great, but I would like to abstract this method a bit further by providing SetOwnedCollectionMapping() . This means the calling code can

Combine Multiple Linq Expressions [duplicate]

☆樱花仙子☆ 提交于 2019-12-04 16:07:12
This question already has an answer here: Combining two expressions (Expression<Func<T, bool>>) 6 answers I'm in the process of refactoring some code, attempting to make it more self-documenting. The current code has a query over an OData service which looks like this: return context.MessageLog.Where ( x => ( x.Status == MessageStatus.Success || x.Status == MessageStatus.Failure ) && x.Direction == MessageDirection.Inbound && x.ResponseDate == new DateTimeOffset(new DateTime(1900, 01, 01)) ); I'm hoping to change this to make use of Linq Expressions. I could move all of the logic into a single

Passing multiple Include statements into a repository?

久未见 提交于 2019-12-04 16:05:16
问题 I am trying to figure out a way to pass a collection of include statements into my repository so that I can have it include specific entities. Below is some sample code from my repository. public TEntity GetById(Guid id) { return id != Guid.Empty ? GetSet().Find(id) : null; } private IDbSet<TEntity> GetSet() { return _unitOfWork.CreateSet<TEntity>(); } The GetByID method calls the GetSet to return the entity set. I was thinking, if I could somehow pass in a collection of entities to include

WhereNot linq expression

一曲冷凌霜 提交于 2019-12-04 12:04:54
I am trying to create an extension "WhereNot" So I can use: Dim x = "Hello world " Dim y = x.Split.WhereNot(AddressOf String.IsNullOrEmpty) Note that my aim here is to learn linq expressions; not solve my issue. I craated this function: <Extension()> _ Public Function WhereNot(Of TElement)(ByVal source As IQueryable(Of TElement), ByVal selector As Expression(Of Func(Of TElement, Boolean))) As IQueryable(Of TElement) Return source.Where(GetWhereNotExpression(selector)) End Function I don't know how to switch the boolean flag, will the function Negate do it? answers in both vb.net and C# are

C# Expression to sort generic query by key field

天涯浪子 提交于 2019-12-04 11:50:49
I have a generic method in which I want to sort an IQueryable<T> by its key field (it is safe to assume there is only one). Thus: void DoStuff<T>(...) { IQueryable<T> queryable = ... // given PropertyInfo keyField = ... // given var sortedQueryable = queryable.OrderBy(<some expression here>); ... } How do I define an Expression that will return the keyField property of T so that this will work? This isn't too difficult, but you need to invoke the OrderBy with reflection as you don't know the type of the key field ahead of time. So given the code you already show, you would do something like

How to compare only date part with linq expression?

心已入冬 提交于 2019-12-04 07:23:15
I just want to make Column Filter for grid view. Simple I just want to filter grid view column with some extra stuff. Here I have created one IQueryable that returns queryable result. Here is my code : ------------------------------------------Updated------------------------------------------------ public static IQueryable<T> FilterForColumn<T>(this IQueryable<T> queryable, string colName, string searchText) { if (colName != null && searchText != null) { var parameter = Expression.Parameter(typeof(T), "m"); var propertyExpression = Expression.Property(parameter, colName); System.Linq

Dynamic Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> Expression

﹥>﹥吖頭↗ 提交于 2019-12-04 07:22:07
I am using patterns mentioned here http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application And i am using method below to query EF public virtual IEnumerable<TEntity> Get( Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "") { IQueryable<TEntity> query = dbSet; if (filter != null) { query = query.Where(filter); } foreach (var includeProperty in includeProperties.Split (new char[] { ',' }, StringSplitOptions

How to convert CIL to a LINQ Expression Tree [closed]

廉价感情. 提交于 2019-12-03 16:32:33
Has any work been done on the direct conversion of CIL to LINQ expression trees? This would include class libraries, blogs, books, academic papers, etc. What are the known mismatches between CIL and LINQ Expression API? I have seen a project that significantly extended the Expression API to support an almost complete mapping between C# and LINQ Expressions. What work arounds would be suggested to accommodate any of these mismatches? Is there something fundamentally wrong about converting directly from CIL to LINQ Expressions? If so, why? 来源: https://stackoverflow.com/questions/12824201/how-to

How to build a LambdaExpression from an existing LambdaExpression Without Compiling

北战南征 提交于 2019-12-03 16:14:28
I want to combine two LambdaExpressions without compiling them. This is what it looks like if I do compile them: public Expression<Func<TContainer,bool>> CreatePredicate<TContainer,TMember>( Expression<Func<TContainer,TMember>> getMemberExpression, Expression<Func<TMember,bool>> memberPredicateExpression) { return x => memberPredicateExpression.Compile()(getMemberExpression.Compile()(x)); } That's obviously not the fastest way to get the target expression from the provided arguments. Also, it makes it incompatible with query providers like LINQ to SQL that do not support C# method calls. From