dynamic-linq

How to access items in a dynamic list?

蓝咒 提交于 2019-12-02 01:20:11
I am trying to figure out how to enumerate the results from a dynamic LINQ .Select(string selectors) in .NET 4.5. The dynamic linq comes from the System.Linq.Dynamic namespace. Edit: I am also including System.Linq . I have a method that looks like this: public void SetAaData(List<T> data, List<string> fields) { if (data == null || data.Count == 0) { return; } var dynamicObject = data.AsQueryable().Select("new (" + string.Join(", ", fields) + ")"); _aaData = dynamicObject; } If I step through the code, I can examine dynamicObject and enumerate it to view the results (which are correct). The

Dynamic LINQ query to get Field value from Database

时光毁灭记忆、已成空白 提交于 2019-12-01 16:51:08
is it possible? Public String Get_Filed_By_Id(string table_Name,String Field_Name,string PK_val) { string strRes=""; using(mydbcontext db=new mydbcontext()) { var x=db.table_Name.Where(p=>p.Id=PK_val).FirstOrDefault().Field_Name; strRes=Convert.Tostring(x); } return strRes; } OR var x=(from o in db.table_Name where o.Id=PK_val select o.Field_Name).FirstOrDefault(); Here, i'm passing Table_Name , Column_Name and the Condition value( PK_val ) to Get the Column_Name from Table_Name within a Certain Condition( Id=Pk_val ). Is it possible?? Ivan Stoev Is it possible?? Yes, it is. First, some

Dynamic LINQ query to get Field value from Database

萝らか妹 提交于 2019-12-01 15:40:36
问题 is it possible? Public String Get_Filed_By_Id(string table_Name,String Field_Name,string PK_val) { string strRes=""; using(mydbcontext db=new mydbcontext()) { var x=db.table_Name.Where(p=>p.Id=PK_val).FirstOrDefault().Field_Name; strRes=Convert.Tostring(x); } return strRes; } OR var x=(from o in db.table_Name where o.Id=PK_val select o.Field_Name).FirstOrDefault(); Here, i'm passing Table_Name , Column_Name and the Condition value( PK_val ) to Get the Column_Name from Table_Name within a

Dynamic Linq - no property or field exists in type 'datarow'

隐身守侯 提交于 2019-12-01 14:24:18
I am using Northwind Customers Table where I fill the dataset and get the datatable. I am trying to use dynamic linq and want to select columnName dynamically var qry = MyDataTable.AsEnumerable().AsQueryable().Select("new(Country)"); Right now I have hard coded country but even then I get this error No property or field 'Country' exists in type 'datarow' I would like to eventually change this query to take the column name dynamically. Please help!!! thanks. The important hint is here (in bold): No property or field 'Country' exists in type 'datarow' The extension method AsEnumerable of the

Dynamic Linq - no property or field exists in type 'datarow'

谁说胖子不能爱 提交于 2019-12-01 13:01:13
问题 I am using Northwind Customers Table where I fill the dataset and get the datatable. I am trying to use dynamic linq and want to select columnName dynamically var qry = MyDataTable.AsEnumerable().AsQueryable().Select("new(Country)"); Right now I have hard coded country but even then I get this error No property or field 'Country' exists in type 'datarow' I would like to eventually change this query to take the column name dynamically. Please help!!! thanks. 回答1: The important hint is here (in

Dynamic linq: Is there a way to access object data by index?

試著忘記壹切 提交于 2019-12-01 08:10:05
I need some in-memory filtering with Dynamic Linq. My objects have only a indexer: public object this[int index] { } The access to my data is like: object[0], object[1],... So my query is like this: // get FilterText from user at runtime // eg. filterText can be: [0] > 100 and [1] = "wpf" collection.AsQueryable().where(filterText); Is there any way to do this? I have some news for you. It is actually possible... BUT! (Yes, there´s a but). I assume you are using the dynamic Linq library. You must then use the "it"-keyword to be able to specify the current object to which you wish to apply your

How to build a nested query with the dynamic LINQ library

二次信任 提交于 2019-12-01 07:16:48
How can I build the following LINQ query with the Dynamic Linq library (System.Linq.Dynamic)? var roles = rolesCollection.Where(r => r.AssignedUsers.Where(u => u.Name.FirstName == "Patrick").Count() > 0); rolesCollection and AssignedUsers are collections which implement the IEnumerable interface. I was thinking about doing something like this: rolesCollection.Where("AssignedUsers.Where(\"Name.FirstName == 'Patrick'\").Count() > 0"); But that doesn't work. A ParseException with the message "No applicable aggregate method 'Where' exists" is thrown. Thanks in advance. Adrian Iftode Try this:

How to build a nested query with the dynamic LINQ library

落爺英雄遲暮 提交于 2019-12-01 04:56:52
问题 How can I build the following LINQ query with the Dynamic Linq library (System.Linq.Dynamic)? var roles = rolesCollection.Where(r => r.AssignedUsers.Where(u => u.Name.FirstName == "Patrick").Count() > 0); rolesCollection and AssignedUsers are collections which implement the IEnumerable interface. I was thinking about doing something like this: rolesCollection.Where("AssignedUsers.Where(\"Name.FirstName == 'Patrick'\").Count() > 0"); But that doesn't work. A ParseException with the message "No

Dynamic linq Building Expression

你离开我真会死。 提交于 2019-12-01 00:33:17
I need to create a dynamic linq expression for a dynamic search.The basic search is working but it fails to work with collection. I am able to get the book's title and author but fails to get the required page heading. I get the exception in line "left11 = Expression.Property(page1, "Heading");" . I think the expression that i built is unable to recognise the List. How could this be possible? Please see the below code and stacktrace exception. using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks;

How to Type Cast dynamically to string while using Contains in Dynamic LINQ?

纵然是瞬间 提交于 2019-11-30 22:33:05
I want to use Dynamic LINQ Query to Search with some text in all Properties in a class. i am using following function to create expression. I am passing property name and search text to the method. In that method if the property type is String then it is working fine. if the property type is int, DateTime, GUID. then it is not working. As we know Contains method only for array of elements or for string. I am thinking the value to property should type cast to string. So How to do it? Solution with Explanation is help full. i Collected code from this . public static Expression<Func<T, bool>>