dynamic-linq

Creating dynamic expression for entity framework

孤街醉人 提交于 2019-12-30 07:08:08
问题 I've created a generic expression builder that builds up a predicate based on collection of conditions. I pass the predicate to a generic method in the repository. I think that expression builder works fine and creates the desired predicate although the SQL script generated by Entity Framework is not as I expected. I've read many questions and article regarding dynamic query or LinqKit and expression builder to this issue and the most relevant was this comment. I really appreciate if you

Converting Expression<T, bool> to String

荒凉一梦 提交于 2019-12-28 11:43:22
问题 I need a way to recreate dynamically generated reports at some point in the future. Long story short, I need to store a specific linq query (different for each report) into database and then execute the query with dynamic Linq later on. This is all good, but I can't find a way to convert expression to string. As in: Expression<Func<Product, bool>> exp = (x) => (x.Id > 5 && x.Warranty != false); should become: "Product.Id > 5 && Product.Warranty != false" Is there a way to do that? 回答1: This

System.LINQ.Dynamic: Select(“ new (…)”) into a List<T> (or any other enumerable collection of <T>)

梦想与她 提交于 2019-12-27 11:41:25
问题 Say I have a DataTable with four columns, Company (string), Fund (string), State (string), Value(double): table1.Rows.Add("Company 1","Fund 1","NY",100)); table1.Rows.Add("Company 2","Fund 1","CA",200)); table1.Rows.Add("Company 3","Fund 1","FL",300)); table1.Rows.Add("Company 4","Fund 2","CA",400)); table1.Rows.Add("Company 5","Fund 1","NY",500)); table1.Rows.Add("Company 6","Fund 2","CA",600)); table1.Rows.Add("Company 7","Fund 3","FL",700)); I want to use System.LINQ.Dynamic to build a

How to get Predicate<T> from string expressions at runtime

牧云@^-^@ 提交于 2019-12-26 11:52:13
问题 In Winform application using EntityFramework, I implement a generic Search / Filter UI Components using BindingSource of the BaseForm and build search/filter string expression dynamically from user inputs and properties of the DataSource of BindingSource (Context entity). Find and Filter aren't supported by the BindingSource in EntityFramework, because the query result of ObjectContext or DataContext was IEnumerable type, which didn't implement IBindingList interface ref As a workaround I

How to get Predicate<T> from string expressions at runtime

这一生的挚爱 提交于 2019-12-26 11:48:50
问题 In Winform application using EntityFramework, I implement a generic Search / Filter UI Components using BindingSource of the BaseForm and build search/filter string expression dynamically from user inputs and properties of the DataSource of BindingSource (Context entity). Find and Filter aren't supported by the BindingSource in EntityFramework, because the query result of ObjectContext or DataContext was IEnumerable type, which didn't implement IBindingList interface ref As a workaround I

How to get Predicate<T> from string expressions at runtime

拟墨画扇 提交于 2019-12-26 11:48:16
问题 In Winform application using EntityFramework, I implement a generic Search / Filter UI Components using BindingSource of the BaseForm and build search/filter string expression dynamically from user inputs and properties of the DataSource of BindingSource (Context entity). Find and Filter aren't supported by the BindingSource in EntityFramework, because the query result of ObjectContext or DataContext was IEnumerable type, which didn't implement IBindingList interface ref As a workaround I

Dynamic linq syntax for subquery

左心房为你撑大大i 提交于 2019-12-25 06:38:37
问题 I want to have the following query in Dynamic LINQ.. I have tried some solutions but have not succeeded yet. select SUM([Value1]) AS [Sum] ,[Dim1] AS [Primary], [Dim2] AS [Secondary] from ( SELECT value1, dim1, dim2 FROM [BudgetLine] WHERE [BudgetID] = 4 ) as a GROUP BY [Dim1], [Dim2] My current code looks like this, but I need to rewrite it to give me the SQL above. var query = (DatabaseConnection.DataMemoryContext.GetTable<BudgetLineEntity>().AsQueryable() .Where(String.Format("BudgetID={0}

How to use Dynamic LINQ in MVC4?

安稳与你 提交于 2019-12-25 05:18:22
问题 This is the default action from the "View" of my MVC4 application. public ActionResult Index(string sort = "R_ResDate", string sortdir = "DESC", int page = 1) { List<Result> results = modRes.Results.ToList(); var results = from r in results orderby r.R_ResultDate descending select r; return View(results); } Where modRes is a Model class, I wanted to use the sort column, sortDir, and page arguments in the dynamic linq to derive the results. Any help would be appreciated. 回答1: You can use this

Use Dynamic LINQ Library with join

别等时光非礼了梦想. 提交于 2019-12-25 03:15:52
问题 Following is the UI : And this is code snippet i am using to fire dynamic where clause : public void bind() { string filter = ""; if (!string.IsNullOrEmpty(txtPart.Text)) { filter = filter + "masterinv.inv_item_id = " + txtPart.Text; } if (!string.IsNullOrEmpty(txtDescription.Text)) { if (!string.IsNullOrEmpty(filter)) { filter = filter + " || masterinv.description = " + txtDescription.Text; } else { filter = filter + "masterinv.description = " + txtDescription.Text; } } if (!string

How to implement SelectMany in System.Linq.Dynamic ExpressionParser

我怕爱的太早我们不能终老 提交于 2019-12-24 16:57:15
问题 I'm trying to implement the SelectMany statement inside of the dynamic linq expresion parser, such that I could run a query like so: Customers.Select("Orders.SelectMany(OrderItems)") Such that it would be equivilent to the linq query: Customers.Select(cust => cust.Orders.SelectMany(ord => ord.OrderItems)) I've tried adding SelectMany to the IEnumerableSignatures of System.Linq.Dynamic.ExpressionParser, but it looks like there's more I need to do. I've looked into this codeplex project but