dynamic-linq

Linq dynamic where count?

泄露秘密 提交于 2019-11-30 16:33:24
Is it possible to use list in where. I want somethink like this: public class Customer { string FirtsName; string LastName; int Number; ..... } I want to filter customers with using checkboxes. If I select FirstName and Number then where clause will be generated .where(x=> x.FirstName == "SomeFirstName" && x.Number == someNumber) If I select only number then where clause will be generated .where(x.Number == someNumber) If I select FirstName, LastName and Number then where clause will be generated .where(x=> x.FirstName == "SomeFirstName" && x.Number == someNumber && x.LastName == "LastName") I

Dynamic LINQ: Specifying class name in new clause

邮差的信 提交于 2019-11-30 15:37:28
With Dynamic LINQ, what changes need to be done to have fields of the given class? For example, how can the following C# query be reproduced in DLinq: var carsPartial = cars.Select(c => new {c.year, c.name, make = new maker() {name = c.make.name} }).ToList(); I have applied the changes mentioned in this answer https://stackoverflow.com/a/1468357/288747 to allow the return type to be the calling type rather than an anonymous type. With the class definition is as follows (if it helps): class car { public int vid; public int odo; public int year; public string name; public maker make; } class

Call function in dynamic linq

亡梦爱人 提交于 2019-11-30 14:38:58
I'm trying to call a function in a dynamic linq select statement, but im getting error: No property or field 'A' exists in type 'Tuple2' Example code: void Main() { var a = new Tuple<int, int>(1,1); var b = new[]{ a }; var q = b.AsQueryable().Select("A.Test(it.Item1)"); q.Dump(); } public static class A { public static int Test(int i) { return i++; } } How should I change my code to get this working? If I call built in function Convert.ToInt32 for example it works fine. var q = b.AsQueryable().Select("Convert.ToInt32(it.Item1)"); Also how do I cast a property using dynamic linq? var q = b

Linq dynamic where count?

纵饮孤独 提交于 2019-11-29 23:48:52
问题 Is it possible to use list in where. I want somethink like this: public class Customer { string FirtsName; string LastName; int Number; ..... } I want to filter customers with using checkboxes. If I select FirstName and Number then where clause will be generated .where(x=> x.FirstName == "SomeFirstName" && x.Number == someNumber) If I select only number then where clause will be generated .where(x.Number == someNumber) If I select FirstName, LastName and Number then where clause will be

How to create dynamic lambda based Linq expression from a string in C#?

≡放荡痞女 提交于 2019-11-29 23:22:12
问题 I'm having some difficulty creating Lambda-based Linq expressions from a string. Here is my basic case using this sample object/class: public class MockClass { public string CreateBy { get; set; } } Basically I need to convert a string like this: string stringToConvert = “x => x.CreateBy.Equals(filter.Value, StringComparison.OrdinalIgnoreCase”; Into a to predicate/linq expression: System.Linq.Expressions.Expression<Func<T, bool>> or in this example System.Linq.Expressions.Expression<Func

Dynamic LINQ: Specifying class name in new clause

懵懂的女人 提交于 2019-11-29 23:05:47
问题 With Dynamic LINQ, what changes need to be done to have fields of the given class? For example, how can the following C# query be reproduced in DLinq: var carsPartial = cars.Select(c => new {c.year, c.name, make = new maker() {name = c.make.name} }).ToList(); I have applied the changes mentioned in this answer https://stackoverflow.com/a/1468357/288747 to allow the return type to be the calling type rather than an anonymous type. With the class definition is as follows (if it helps): class

Call function in dynamic linq

╄→гoц情女王★ 提交于 2019-11-29 21:15:14
问题 I'm trying to call a function in a dynamic linq select statement, but im getting error: No property or field 'A' exists in type 'Tuple2' Example code: void Main() { var a = new Tuple<int, int>(1,1); var b = new[]{ a }; var q = b.AsQueryable().Select("A.Test(it.Item1)"); q.Dump(); } public static class A { public static int Test(int i) { return i++; } } How should I change my code to get this working? If I call built in function Convert.ToInt32 for example it works fine. var q = b.AsQueryable(

how to get value of a definite Column name in c# / Linq?

你离开我真会死。 提交于 2019-11-29 12:34:44
I want to know if it possible to get value of a definite columns name ? For exemple SELECT NAME FROM PERSON; string NAME; <--- Column name string fundPerson; fundPerson = context.PERSON.Where(a => a... == NAME); The problem is that the column name can change, it is not always the "NAME" column. Hence I need a solution where I can dynamically pass a column name to the query. You want to the source code in C# to create a linq query that compiles to SELECT NAME FROM PERSON under Linq to SQL or Linq to Entity Framework? IEnumerable<string> names = from x in context.PERSONS select x.Name; OR

Dynamic LINQ DateTime Comparison String Building - Linq To Entities

£可爱£侵袭症+ 提交于 2019-11-29 10:39:55
I'm using the dynamic LINQ library by Scott Guthrie together with Entity Framework and C#. I have to build my where string into a variable based on several factors and then pass the string variable to the where clause. For some reason, this will work: ContactList = ContactList.Where("DateAdded >= @0", DateTime.Parse("12/1/2012")); But this will not work string WhereClause = string.Format("DateAdded >= {0}", DateTime.Parse("12/1/2012")); ContactList = ContactList.Where(WhereClause); As mentioned, I need to use it in the version of passing the variable. Anyone know why the second doesn't work?

How to use Enums with Dynamic Linq?

笑着哭i 提交于 2019-11-29 04:22:32
I would like to use enumerations in my dynamic LINQ queries. Is it possible, and if, how? Consider the code bellow: using System; using System.Collections.Generic; using System.Linq; using System.Linq.Dynamic; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { Room aRoom = new Room() { Name = "a Room" }; Room bRoom = new Room() { Name = "b Room" }; Room cRoom = new Room() { Name = "c Room" }; House myHouse = new House { Rooms = new List<Room>(new Room[] { aRoom }), MainRoom = aRoom }; House yourHouse = new House() { Rooms = new List<Room>(new Room[] { bRoom,