expression-trees

How do I create a generic Expression that has an expression as a parameter

醉酒当歌 提交于 2019-12-09 01:07:18
问题 There is a DisplayNameFor(x=>x.Title) helper in ASP.Net MVC. I want to implement something similar in behavior. I want to have a method that accepts an expression based on User class ( u=>u.Birthdate or u=>u.Name), a operand (Greater, Less, Equal) and a value like DateTime.Now and returns an expression u=>u.Birthdate > DateTime.Now I understand that I'll have to build resulting expression manually from pieces. What i can't wrap my head around is passing in and handling of property expression.

Save Entity Framework Linq Query to database

ぐ巨炮叔叔 提交于 2019-12-08 22:22:18
问题 I was wondering if we can convert a Linq Query on the Entity Framework and save the query to the database by converting it to an Expression Tree and Serializing. Can someone please help me on this and point me in a right direction whether this can be done or not. Any help is greatly appreciated on this. Thanks, Ajay. 回答1: i released a library for that purpose just yesterday. Serialize.Linq. It serializes linq expressions to xml, json or binary. using System.Linq.Expressions using Serialize

LINQ-to-SQL : Convert Func<T, T, bool> to an Expression<Func<T, T, bool>>

心已入冬 提交于 2019-12-08 19:38:08
问题 LINQ-to-SQL has been a PITA for me. We're using it to communicate to the database, and then send entities via WCF to a Silverlight app. Everything was working fine, until it came time to start editing (CUD) the entities, and their related data. I was finally able to devise two for loops that allowed the CUD. I tried to refactor them, and I was so close, until I learned that I can't always do Lambda with L2S. public static void CudOperation<T>(this DataContext ctx, IEnumerable<T> oldCollection

Is it possible to have an out ParameterExpression?

自古美人都是妖i 提交于 2019-12-08 15:24:27
问题 I want to define a Lambda Expression with an out parameter. Is it possible to do it? Below are code snippets from a C# .Net 4.0 console app that I tried. As you can see in Procedure25 I can use lambda expressions to define a delegate that has an output parameter, however, when I want to use linq expressions to do the same, the code in procedure 24 fails with: System.ArgumentException was unhandled Message=ParameterExpression of type 'System.Boolean' cannot be used for delegate parameter of

Building Dynamic GroupBy Selector Expression Tree With Multiple Properties

末鹿安然 提交于 2019-12-08 12:37:03
问题 I am to build a dynamic Expression Tree for GroupBy. All i want to achieve is like this. var NestedGrouped = listOfPerson.GroupByMany(x => x.Name,x=>x.Age).ToList(); My Person Class is like :- class Person { public string Name{ get; set; } public int Age{ get; set; } public float Salary{ get; set; } } public class GroupResult { public object Key { get; set; } public int Count { get; set; } public IEnumerable Items { get; set; } public IEnumerable<GroupResult> SubGroups { get; set; } public

Accessing Method based Embodied Members to build expression trees

会有一股神秘感。 提交于 2019-12-08 11:03:34
问题 Trying to build an order by expression using expression trees. But I am unable to access an expression bodied property of the query result's class. This is the class structure: public class AssetFileRecord : IAuditable, IEntity, INavigateToCustomValues { public AssetFileRecord() { this.UpdatedTimeStamp = DateTime.UtcNow; } public AssetFileRecord GetRecord() { return this; } public Guid Id { get; set; } public int DisplayId { get; set; } public string AssetTagNumber { get; set; }

Recursive evaluate() in expression tree class

痴心易碎 提交于 2019-12-08 10:12:15
问题 I am new in Java and trying to add evaluate method to my class. The ExpTree class and its testing program is given to me. I wrote my code as I learned in the class, but do not know why it does not work. An evaluate() method, which returns the arithmetic evaluation of the ExpTree. This should be done recursively, so you will need 2 methods to do it. In the case where it would result in division or mod by 0, it should throw a new ArithmeticException with a descriptive String. If the tree is

using expression trees to compare objects by a single property nets InvalidOperationException

天大地大妈咪最大 提交于 2019-12-08 09:00:10
问题 I am trying to use Expression Trees because based on description, that seems to be the most correct (performant, configurable) approach. I expect to be able to craft a statement that gets the first item from the existingItems collection that matches the propertyNameToCompareOn value of the incomingItem. I have a method with the following signature and simulated code body... DetectDifferences<T>(List<T> incomingItems, List<T> existingItems) { var propertyNameToCompareOn =

Deep Clone with Expression.New and Expression Trees

非 Y 不嫁゛ 提交于 2019-12-08 08:07:48
问题 I have two Generated Interfaces IPerson and IAddress . However I have defined Property Interfaces which Inherit from those base Interfaces Interfaces public interface IPerson_Name : IPerson { String Name{get;set;}} public interface IPerson_Addresses : IPerson { ICollection<IAddress> Addresses{ get; set; } IAddress NewAddress(); } public interface IAddress_Line1 : IAddress { String Line1 { get; set; } } Then I have two implementations of each of the base interfaces Implementation public class

Could not find a matching type in ExpressionSerialization.dll

99封情书 提交于 2019-12-08 07:51:08
问题 I use ExpressionSerialization library for serializing Expression Tree but get me an error Could not find a matching type WCF Service : public class Person { public int ID { get; set; } public string Name { get; set; } } [ServiceContract] public interface IService1 { [OperationContract(Name = "GetByPredicate")] List<Person> Get(XElement expression); [OperationContract] List<Person> Get(); } public class Service1 : IService1 { private readonly List<Person> _persons; public Service1() { var p =