dynamic-linq

Strange Exception thrown using Dynamic Linq Entity Framework Query

£可爱£侵袭症+ 提交于 2019-12-13 14:12:59
问题 I have a gallery entity framework class,and I'm attempting to use the Dynamic Linq Library posted on ScottGu's blog to query the entity set. The failing line of code reads: return context.Galleries.OrderBy(sidx + " " + sord).Skip(page * rows).Take(rows).ToList(); sidx=="Name", and sord=="desc". The Gallery object does have a property called "Name". However, when executed, i get the following exception: 'Title' could not be resolved in the current scope or context. Make sure that all

Natural sort with Dynamic Linq including multiple sorting parameters

早过忘川 提交于 2019-12-13 04:24:15
问题 As the title describes, is there any way I can achieve natural sort using Dynamic Linq including support for multiple sorting parameters? Preferably I would like to do something like this (using a custom IComparer): List<Invoice> invoices = Provider.GetInvoices(); invoices = invoices .AsQueryable() .OrderBy("SortingParameter1 ASC, SortingParamaeter 2 ASC", new NaturalSort()) .ToList(); 回答1: DynamicLinq does not have method OrderBy that takes IComparer<T> as parameters, so you can't pass

Modify query generated by Linq dynamically

眉间皱痕 提交于 2019-12-13 03:55:45
问题 I'm working on a project that is using Oracle and DynamicLinq, results that DynamicLinq is building a query that is really slow: SELECT /*FIELDS*/ FROM MYTABLE WHERE (("STRT_DT" >= TO_TIMESTAMP('2015-07-09 00:00:00.000', 'YYYY-MM-DD HH24:MI:SS.FF')) AND ("STRT_DT" <= TO_TIMESTAMP('2018-07-04 00:00:00.000', 'YYYY-MM-DD HH24:MI:SS.FF'))) The issue is that is generating the query using TO_TIMESTAMP('2018-07-04 00:00:00.000', 'YYYY-MM-DD HH24:MI:SS.FF') instead of TO_DATE : STRT_DT >= TO_DATE('09

Linq: Dynamic Query Contruction: query moves to client-side

白昼怎懂夜的黑 提交于 2019-12-13 00:37:27
问题 I've been following with great interest the converstaion here: Construct Query with Linq rather than SQL strings with regards to constructing expression trees where even the table name is dynamic. Toward that end, I've created a Extension method, addWhere, that looks like: static public IQueryable<TResult> addWhere<TResult>(this IQueryable<TResult> query, string columnName, string value) { var providerType = query.Provider.GetType(); // Find the specific type parameter (the T in IQueryable<T>

Dynamically Linq Select Cast To IEnumerable

六眼飞鱼酱① 提交于 2019-12-12 23:53:02
问题 I'm creating a Widget builder which Dynamically takes in Queries and returns a datatable with the results. NOTE: this uses Dynamic Linq to take in string queries the library source can be found here My only issue is casting the results set to an IEnumerable. public DataTable GetEntityData<D>(string Query, int NumbOfResults, List<string> Columns) where D : class { ObjectContext objectContext = ((IObjectContextAdapter)this).ObjectContext; var FDW = (objectContext.CreateObjectSet<D>() as

how to order by a dynamic column name in EntityFramework?

耗尽温柔 提交于 2019-12-12 20:30:07
问题 I am trying to get following code working , This was working fine for MSSQL , but since i changed to use mySql it is not working records.Content = db.areas .Where(x => x.Name.Contains(filter))) .OrderBy("dated desc") .ToList(); I get the error " Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information." string colName = "datedD" ; how to order by depneding on colName variable ? ` 回答1: Try this string filterString = "dated"; bool

Logic Evaluator in c# (Evaluate Logical (&& ,|| ) expressions)

和自甴很熟 提交于 2019-12-12 07:19:51
问题 In my project there is a Logic evaluation section, it take input as a string which contains logical expressions ( true/false ) . I want to evaluate this string and return a final Boolean value. string Logic="1&0|1&(0&1)" //string Logic="true AND false OR true AND (false AND true)" This will be my Logic . The length might increase. Is there any way to Evaluate this expression from LINQ / Dynamic LINQ ? 回答1: a way without any third party libraries is to use a DataTable with expression. There

Dynamic Linq Select -How to extract the results

↘锁芯ラ 提交于 2019-12-12 04:59:58
问题 I have a dynamic Linq Select statement of the form var projection = result.AsQueryable().Select(string.Format("new({0},{1})", model.XtabRow, model.XtabColumn)); This works fine and produces an IQueryable of Anonymous types. However I an unable to convert it into IEnumerable to use linq on it as AsEnumerable method seems to be missing. I had to use reflection to extract field values in the end There must be a better way - Any help would be great Thanks 回答1: You can try something like this var

How to select non nullables from nullable relation in Entity Framework

萝らか妹 提交于 2019-12-11 23:33:38
问题 I am making a reporting tool that is based off Entity Framework and Scott Guthrie's Dynamic Linq library. I have run into a snag when trying to select a non nullable field from a related table when the related record isnt always there. For example, I have a Participant table that has a nullable foreign key to a Team table. This is because some participants will be on a team and some wont. The snag is that I want to pull a report that shows a list of participants along with some of their team

How can I access the result of dynamic linq with dynamic key/value pairs of IEnumerable?

点点圈 提交于 2019-12-11 20:15:20
问题 I have a Dynamic Linq query, through which am trying to access grouped data, grouped on two columns, and 1 columns on which aggregation function is used. var gFieldList = new List<string>() { "Supplier", "Country" }; var sFieldList = new List<string>() { "Sales"}; var gField = string.Join(", ", gFieldList.Select(x => "it[\"" + x + "\"] as " + x)); var sField = string.Join(", ", sFieldList.Select(y => "Sum(Convert.ToDouble(it[\""+y+"\"])) as "+y)); var dQueryResult = dataTable .AsEnumerable()