dynamic-linq

Dynamic LINQ Cast issue

廉价感情. 提交于 2021-02-08 08:13:14
问题 When I try to execute this ESQL (Cast int to string) with dynamic linq (from this link) queryable.Where("CAST(PositionID AS Edm.String).Contains(@0)", paramsObj); //PositionID is Int32 it throw exception ')' or ',' expected My Entity Framework version is 4.0. Any idea how to resolve this problem ? Thanks in advance, Brian 回答1: you cann't use as inside function call, try change your code like this queryable.Where("(PositionID.ToString().Contains(@0))", paramsObj); //PositionID is Int32 UPDATE:

Dynamic LINQ Cast issue

泄露秘密 提交于 2021-02-08 08:06:01
问题 When I try to execute this ESQL (Cast int to string) with dynamic linq (from this link) queryable.Where("CAST(PositionID AS Edm.String).Contains(@0)", paramsObj); //PositionID is Int32 it throw exception ')' or ',' expected My Entity Framework version is 4.0. Any idea how to resolve this problem ? Thanks in advance, Brian 回答1: you cann't use as inside function call, try change your code like this queryable.Where("(PositionID.ToString().Contains(@0))", paramsObj); //PositionID is Int32 UPDATE:

Dynamic LINQ Cast issue

会有一股神秘感。 提交于 2021-02-08 08:04:27
问题 When I try to execute this ESQL (Cast int to string) with dynamic linq (from this link) queryable.Where("CAST(PositionID AS Edm.String).Contains(@0)", paramsObj); //PositionID is Int32 it throw exception ')' or ',' expected My Entity Framework version is 4.0. Any idea how to resolve this problem ? Thanks in advance, Brian 回答1: you cann't use as inside function call, try change your code like this queryable.Where("(PositionID.ToString().Contains(@0))", paramsObj); //PositionID is Int32 UPDATE:

Linq dynamic having issue with double quote

强颜欢笑 提交于 2021-01-29 18:39:25
问题 I am using System.Linq.Dynamic; to generate dynamic linq query which featch records from db context. I generate where clause in string format for dynamic linq, It works perfectly if input does not have any double quote. However, it throws error once input string contains double quote. I followed Stack Overflow existing solution dynamiclinq-escaping-double-quotes-inside-strings but it does not helped because I wanted to use LIKE operator. I'm using Contains condition in my where clause because

Multiple Values Contains with Dynamic Linq

萝らか妹 提交于 2021-01-28 19:44:49
问题 How to use Multiple value with Contain in Dynamic Linq. Expected With Normal Linq : using System; using System.Linq; public class Simple { public static void Main() { string[] names = { "Burke", "Laptop", "Computer", "Mobile", "Ahemed", "Sania", "Kungada", "David","United","Sinshia" }; string[] vars = {"i","a"}; var query = names.Where(i=> vars.Any(j=>i.Contains(j))).ToList(); Console.WriteLine(query.Count); } } Expected SQL SELECT * FROM User WHERE (NAME LIKE '%a%'OR NAME LIKE '%b%') Tried

No applicable method 'Select' exists in type 'DataRow'

天涯浪子 提交于 2020-06-29 03:32:13
问题 I have a data table result and I converted it to Enumerable using AsEnumerable extension. var dataTableToEnumerable = dataTable.AsEnumerable(); Now Im doing a groupBy on it using Linq Dynamic Extensions and it works fine but I cant process Select() , Sum() , Min() etc on the aggregrated result. But methods like Count(),First(),FirstOrDefault() exist. dataTableToEnumerable.AsQueryable().Where("(it[\"yoko\"] != null&&it[\"price\"] != null)") .GroupBy("new(it[\"proposalid\"] as proposalid,it[\

Convert my value type to nullable equivalent

荒凉一梦 提交于 2020-04-13 03:56:15
问题 I have an ad-hoc reporting system; I have no compile-time knowledge of the source type of queries or of the required fields. I could write expression trees at runtime using the System.Linq.Expressions.Expression factory methods, and invoke LINQ methods using reflection, but Dynamic LINQ is a simpler solution. The reporting system is to allow for queries which returns the result of a LEFT JOIN. There are fields in the joined table which are NOT NULL in the database; but because this is a LEFT

Convert my value type to nullable equivalent

烈酒焚心 提交于 2020-04-13 03:55:12
问题 I have an ad-hoc reporting system; I have no compile-time knowledge of the source type of queries or of the required fields. I could write expression trees at runtime using the System.Linq.Expressions.Expression factory methods, and invoke LINQ methods using reflection, but Dynamic LINQ is a simpler solution. The reporting system is to allow for queries which returns the result of a LEFT JOIN. There are fields in the joined table which are NOT NULL in the database; but because this is a LEFT

How to make Exists with Dynamic Linq

﹥>﹥吖頭↗ 提交于 2020-02-25 03:18:27
问题 How to do I make exists with dynamic LINQ? I'm trying to create an SQL clause with dynamic LINQ. I researched a lot of and not found an satisfactory answer. I try convert the SQL query as follows: SQL select * from Documento where exists( select 1 from Titulo where Documento.codDocumento = Titulo.codDocumento and Documento.codEmpresa = Titulo.codEmpresaDocumento and Titulo.codFluxoConta = 'SomeValue' and Titulo.codEmpresaFluxoConta = 'StringNumerical') In common LINQ I did as follows: var

How can I sort a list based on a user's selections in ASP.NET MVC?

两盒软妹~` 提交于 2020-02-20 09:00:39
问题 I have a list of customers that can be sorted by anywhere from 1 to 6 fields based on a user's selection. The sort fields can be in any order. If I know the fields and the sequence ahead of time, sorting is easy: customers = customers .OrderBy(c => c.LastName) .ThenBy(c => c.City) .ThenBy(c => c.Age).ToList(); How would I pass in the sort fields at runtime? Is there a way to do something like this? string sortField1 = "State"; string sortField2 = "City"; string sortField3 = "Type"; customers