linq-expressions

Pass LINQ expression as parameter to where clause

心已入冬 提交于 2021-02-20 05:18:31
问题 Please read the question carefully before voting to close it. That is not a duplicate. I am trying to build a generic method that returns list of entities of type T joined to logs of type AuditLog. Here is a LEFT JOIN interpretation in LINQ that I use var result = from entity in entitySet from auditLog in auditLogSet.Where(joinExpression).DefaultIfEmpty() select new { entity, auditLog }; return result.GroupBy(item => item.entity) .Select(group => new { Entity = group.Key, Logs = group.Where(i

Extracting Func<> from Expression<>

匆匆过客 提交于 2021-02-08 13:14:22
问题 I wanna extract the Func<> from the following Expression : Expression<Func<IQueryable<Entity>, IOrderedQueryable<Entity>>> order = q => q.OrderByDescending(c=>c.FullName); Func<IQueryable<Entity>, IOrderedQueryable<Entity>> orderFunc = ? How can I do it? Edit : And how can we convert Func<IQueryable<Entity>, IOrderedQueryable<Entity>> to Expression<Func<IQueryable<Entity>, IOrderedQueryable<Entity>>> ? 回答1: You can use the Compile method to turn any Expresstion<TDelegate> into a TDelegate .

Extracting Func<> from Expression<>

自古美人都是妖i 提交于 2021-02-08 13:12:23
问题 I wanna extract the Func<> from the following Expression : Expression<Func<IQueryable<Entity>, IOrderedQueryable<Entity>>> order = q => q.OrderByDescending(c=>c.FullName); Func<IQueryable<Entity>, IOrderedQueryable<Entity>> orderFunc = ? How can I do it? Edit : And how can we convert Func<IQueryable<Entity>, IOrderedQueryable<Entity>> to Expression<Func<IQueryable<Entity>, IOrderedQueryable<Entity>>> ? 回答1: You can use the Compile method to turn any Expresstion<TDelegate> into a TDelegate .

Does Expression.ToString() work?

蓝咒 提交于 2020-05-27 21:30:53
问题 I have a generated lambda, but when I want to watch it's like a normal lambda it just doesn't show anything. When I call expr.Body.ToString() I get following: {var compareA; ... } But DebugView for expression works fine: .Lambda #Lambda1<System.Comparison`1[XLinq.Test.Comparers.CustomComparerTest+Test]>( XLinq.Test.Comparers.CustomComparerTest+Test $x, XLinq.Test.Comparers.CustomComparerTest+Test $y) { .Block(System.Int32 $compareA) { $compareA = .Call ($x.A).CompareTo($y.A); .If ($compareA !

Does Expression.ToString() work?

女生的网名这么多〃 提交于 2020-05-27 21:28:47
问题 I have a generated lambda, but when I want to watch it's like a normal lambda it just doesn't show anything. When I call expr.Body.ToString() I get following: {var compareA; ... } But DebugView for expression works fine: .Lambda #Lambda1<System.Comparison`1[XLinq.Test.Comparers.CustomComparerTest+Test]>( XLinq.Test.Comparers.CustomComparerTest+Test $x, XLinq.Test.Comparers.CustomComparerTest+Test $y) { .Block(System.Int32 $compareA) { $compareA = .Call ($x.A).CompareTo($y.A); .If ($compareA !

Does Expression.ToString() work?

佐手、 提交于 2020-05-27 21:25:53
问题 I have a generated lambda, but when I want to watch it's like a normal lambda it just doesn't show anything. When I call expr.Body.ToString() I get following: {var compareA; ... } But DebugView for expression works fine: .Lambda #Lambda1<System.Comparison`1[XLinq.Test.Comparers.CustomComparerTest+Test]>( XLinq.Test.Comparers.CustomComparerTest+Test $x, XLinq.Test.Comparers.CustomComparerTest+Test $y) { .Block(System.Int32 $compareA) { $compareA = .Call ($x.A).CompareTo($y.A); .If ($compareA !

Does Expression.ToString() work?

爷,独闯天下 提交于 2020-05-27 21:24:05
问题 I have a generated lambda, but when I want to watch it's like a normal lambda it just doesn't show anything. When I call expr.Body.ToString() I get following: {var compareA; ... } But DebugView for expression works fine: .Lambda #Lambda1<System.Comparison`1[XLinq.Test.Comparers.CustomComparerTest+Test]>( XLinq.Test.Comparers.CustomComparerTest+Test $x, XLinq.Test.Comparers.CustomComparerTest+Test $y) { .Block(System.Int32 $compareA) { $compareA = .Call ($x.A).CompareTo($y.A); .If ($compareA !

Is this a bug in .Net reflection?

[亡魂溺海] 提交于 2020-02-03 07:57:53
问题 ANSWER is: No, this is not a bug. The difference is in the ReflectedType. So the real question here is: Is there a way of comparing two PropertyInfo objects, for the same property, but reflected from different types, so that it returns true ? Original question This code produces two PropertyInfo objects for the very same property , by using two different ways . It comes that, these property infos compare differently somehow. I have lost some time trying to figure out this out. What am I doing

Is this a bug in .Net reflection?

倖福魔咒の 提交于 2020-02-03 07:57:16
问题 ANSWER is: No, this is not a bug. The difference is in the ReflectedType. So the real question here is: Is there a way of comparing two PropertyInfo objects, for the same property, but reflected from different types, so that it returns true ? Original question This code produces two PropertyInfo objects for the very same property , by using two different ways . It comes that, these property infos compare differently somehow. I have lost some time trying to figure out this out. What am I doing

Is this a bug in .Net reflection?

不问归期 提交于 2020-02-03 07:57:07
问题 ANSWER is: No, this is not a bug. The difference is in the ReflectedType. So the real question here is: Is there a way of comparing two PropertyInfo objects, for the same property, but reflected from different types, so that it returns true ? Original question This code produces two PropertyInfo objects for the very same property , by using two different ways . It comes that, these property infos compare differently somehow. I have lost some time trying to figure out this out. What am I doing