dynamic-linq

Dynamic Linq to Xml example

末鹿安然 提交于 2019-12-20 05:35:13
问题 I need a basic example on how to use System.Linq.Dynamic with Xml. Here’s a functioning statement I want to convert to dynamic Linq: XElement e = XElement.Load(new XmlNodeReader(XmlDoc)); var results = from r in e.Elements("TABLES").Descendants("AGREEMENT") where (string)r.Element("AGRMNT_TYPE_CODE") == "ISDA" select r.Element("DATE_SIGNED"); foreach (var x in results) { result = x.Value; break; } Here’s the approach I am using: string whereClause = "(\"AGRMNT_TYPE_CODE\") == \"ISDA\"";

Dynamic LINQ aggregates on IQueryable as a single query

天大地大妈咪最大 提交于 2019-12-19 04:33:09
问题 I'm building a datagrid library that works on generic IQueryable data sources. At the bottom selected columns will have aggregates: sum, average, count etc. I can compute the sum/average/count individually using the code from this article How to do a Sum using Dynamic LINQ I don't want to run them individually for a datasource, as this would cause multiple queries on the database, I would rather create a single expression tree an execute this as a single query. In static LINQ you'd do all the

Dynamic linq Building Expression

跟風遠走 提交于 2019-12-19 04:08:46
问题 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;

DynamicLINQ - Escaping double quotes inside strings

我只是一个虾纸丫 提交于 2019-12-18 09:39:25
问题 I'm trying to do a dynamic filtering system using the DynamicLINQ library. I have everything working smoothly when you do something like: Find people with First Name is Bob: Context.Users.Where("FirstName == \"Bob\""); But I run into problems when I want to do: Find people with First Name is "Bob" (where Bob is stored in double quotes in the data source). I tried a few different things, including escaping an escaped double quote and a few other variants: Context.Users.Where("FirstName == \"\\

Dynamic LINQ DateTime Comparison String Building - Linq To Entities

隐身守侯 提交于 2019-12-18 05:58:54
问题 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

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

人走茶凉 提交于 2019-12-18 05:15:28
问题 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

Querying Entity with LINQ using Dyanmic Field Name

妖精的绣舞 提交于 2019-12-18 03:00:27
问题 I have created a dynamic search screen in ASP.NET MVC. I retrieved the field names from the entity through reflection so that I could allow the user to choose which fields they wanted to search on instead of displaying all fields in the view. When the search result is Posted back to the controller, I receive a FormCollection containing the FieldName and the Value. I don't know how many fields are being searched on, and the FormCollection only contains fields that were chosen by the user. I

LINQ Dynamic Query Library

廉价感情. 提交于 2019-12-17 19:28:20
问题 I am building an ASP.Net MVC 3 application with Entity Framework 4. When the two pieces of code below are executed, both variables (query1 and query2) have a return type of System.Data.Objects.ObjectQuery<Asset.Model.Equipment> Query1 uses a direct instance of the ObjectContext, however, Query2 uses a repository pattern, ie, it calls GetEquipment in EquipmentService, which in turns calls the same named method in Equipment Repository. Both the methods in the Service and Repository return

How to use GroupBy using Dynamic LINQ

本秂侑毒 提交于 2019-12-17 16:34:26
问题 I am trying to do a GroupBy using Dynamic LINQ but have trouble getting it to work. This is some sample code illustrating the problem: List<dtoMyAlbum> listAlbums = new List<dtoMyAlbum>(); for (int i = 0; i < 5000; i++) { dtoMyAlbum album = new dtoMyAlbum { Author = "My Author", BookID = i, CurrSymbol = "USD", Price = 23.23, Shop = i % 3 == 0 ? "TESCO" : "HMV" }; listAlbums.Add(album); } IQueryable<dtoMyAlbum> mydata = listAlbums.AsQueryable(); int count = mydata.Count(); //var mydataGrouped

How to write dynamic Linq to count matching numbers

断了今生、忘了曾经 提交于 2019-12-14 04:20:27
问题 I have two tables in database. Ticket and TicketNumbers. I would like to write Linq to count the number of tickets that have numbers matching those passed into this function. Since we don't know how many numbers must be matched, the Linq has to be dynamic ... to my understanding. public int CountPartialMatchingTicket(IList<int> numbers) { // where's the code? =_=; } Say for example there are 3 Tickets in the database now and I want to count up all those that have the numbers 3 and 4. (1) 1 2