dynamic-linq

Dynamic table name linq-to-sql dynamic LINQ

三世轮回 提交于 2019-12-11 13:31:04
问题 I want to construct my query dynamically based on the contents user has selected, and I want to do this in LINQ-t0-SQL. I have seen this, but I don't want to use SQL statements with datacontext. On Googling a bit I have a feeling that this can be done using dynamic LINQ. Would someone provide an example of similar scenario with dynamic LINQ? 回答1: Looks like this is the link you need. Update. Some details: you can use the SearchType method from the post to obtain a type using the table name

Safe dynamic column name in dynamic LINQ

末鹿安然 提交于 2019-12-11 08:24:02
问题 I'm trying to create a dynamic WHERE clause with LINQ. I have a working example but I'm worried that it's not safe from SQL injection. The following LINQ code: var oQuery = _db.People.Where("FirstName.Contains(@0)", "kev"); produces the following SQL: SELECT [Extent1].[FirstName] AS [[FirstName], [Extent1].[LastName] AS [[LastName], WHERE [Extent1].[[FirstName] LIKE '%kev%' This works great, but now I want to use a dynamic column name as well. So I was thinking I would do the following: var

Entity Framework Dynamic Where Clause from List<object>

谁说胖子不能爱 提交于 2019-12-11 05:59:39
问题 After scourging the internet I have not been able to find a solution that i can get to work. I am attempting to use dynamic linq to enable the user to build a custom query from a windows form. To hold each where clause I have built an object called WhereClause: public class WhereClause { public int id { get; set; } public string ColumnName { get; set; } public string Operator { get; set; } public string OperatorSymbol { get; set; } public object Value { get; set; } public string AndOr { get;

Convert LINQ query to string, send to remote server to parse into an expression using Roslyn?

巧了我就是萌 提交于 2019-12-11 04:59:38
问题 I have a datasource such as IDataSource : IEnumerable<IDynamicObject> One implementation is quering pure XML-data and another is quering an SQL database. My datasources have no conrete types, and are only working against simple schema-types. In some scenarios, these datasources are instanced in the same runtime-context and other they are accessed over the network. I wasn't to be able to query my datasources with LINQ, and I'm planning on using dynamic objects to only extract and parse the

C# DynamicLinq where clause with Any()

老子叫甜甜 提交于 2019-12-10 18:47:00
问题 I want to run dynamic linq with a string where clause like this: query = db.Customers.Where("Categories.Any(Code == 'Retail')"); Customer entity has collection of categories class Customer { public List<Category> Categories {get;set;} ... } class Category { public Guid Id {get;set;} public string Code {get;set;} } Can anyone please tell me is it possible to do something like this? PS: I need where clause be string. The where clause will be generated at runtime, for this reason I can't use

dynamic query using expression tree

杀马特。学长 韩版系。学妹 提交于 2019-12-10 12:03:28
问题 I have a form in which the user will choose the following from dropdown lists: table_name columnName_to_sort_by columnName_to_search_in The user shall enter Search_text in a text box The form shall draw data from many tables. I want to avoid writing the sort and search for every field for each of the tables. This is why I want to use expression trees. I want to build the query dynamically. I want to write a generic method that will generate the expression tree for the select , where and

Execution-Deferred IQueryable<T> from Dynamic Linq?

痴心易碎 提交于 2019-12-10 01:59:04
问题 I am using Dynamic Linq to perform some queries (sorry but it's my only option). As a result, I am getting an IQueryable instead of an IQueryable<T> . In my case, I want an IQueryable<Thing> where Thing is a concrete type. My query is as such: public IQueryable<Thing> Foo(MyContext db) { var rootQuery = db.People.Where(x => x.City != null && x.State != null); var groupedQuery = rootQuery.GroupBy("new ( it.City, it.State )", "it", new []{"City", "State"}); var finalLogicalQuery = groupedQuery

Displaying Custom Fields in LINQ to Entity Dynamic Select

守給你的承諾、 提交于 2019-12-09 04:11:35
Let's say I have an entity Container with four properties: ContainerID (Integer), ContainerNumber (String), Title (String), and Date (Date). I have a second entity called ContainerCustomFields that has three properties: CustomFieldID (Integer), ContainerID (Integer and Foreign Key), FieldName (String), FieldContent (String). The ContainerCustomFields entity stores user-defined custom fields for the Container entity. The data looks like this: For Container: Container --------- ID | Number | Title | Date | ===================================================== 1 | 10000 | 1st Title | 1/12/2017 |

Displaying Custom Fields in LINQ to Entity Dynamic Select

时光总嘲笑我的痴心妄想 提交于 2019-12-08 05:38:02
问题 Let's say I have an entity Container with four properties: ContainerID (Integer), ContainerNumber (String), Title (String), and Date (Date). I have a second entity called ContainerCustomFields that has three properties: CustomFieldID (Integer), ContainerID (Integer and Foreign Key), FieldName (String), FieldContent (String). The ContainerCustomFields entity stores user-defined custom fields for the Container entity. The data looks like this: For Container: Container --------- ID | Number |

How to filter child collection with linq dynamic

荒凉一梦 提交于 2019-12-07 08:40:53
问题 I'm trying to filter results for user request. For instance you have orders and order details and products is child collection. When user wants to filter by product I'm getting an error because of No property or field 'PRODUCTS' exists in type 'ICollection 1'` I'm writing my query like this. var orders = _uow.Repository<ORDERS>() .Query() .Where("PRODUCTS.HEADING.ToLower().Contains(\"foo\")") .Include("ORDER_DETAILS") .Include("ORDER_DETAILS.PRODUCTS") .ToList(); So it's not possible to