c# - Entityframework 4.0 .CreateQuery<T> and OrderBy exception -


I thought it was fixed in 4.0. I have this method

  public IQueryable & lt; T & gt; All (expression & lt; funk & lt; t, object & gt; & gt; sort) {EntityContext.Creatate & quot; T & gt; (EntityName). Eskenable & lt; T & gt; (). Respectively (sort); }  

Unable to type 'System.Object' for the following throws an exception

type 'System.Int32'. LINQ only supports entity-type model model primitive type casting for units. Source System.Data.Entity

Any ideas how to fix or if it is no way it happens with every call, while the Order string is not datatype

  IQueryable & LT; Blog & gt; All sorted = _pozitory.all (x = & gt; x.Title);  

Since the title is a string by which the order works fine. But it fails with any other datatypes

Since I had come up with the "bad" solution before the mark I thought I would post it

  public IQueryable & lt; T & gt; All (expression & lt; funk & lt; t, object & gt; & gt; sort) {var expresssionType = sort.Body.GetType (); String propertyName = expresssion type == type (System.Linq.Expressions.UnaryExpression)? (UnaryExpression Sorting Body.) .mail. Name: ((Member means) sort. Body Kmel Knam; Var items = entity Kantaks. Kriatti Krenti & lt; T & gt; (EntityName). Ankenebl & lt; T & gt; (); Var Type = Taipf ( T); Var Abhiwyktiproprti = type. GETProperty (propertyName); Var Akspressn parameter = Abhiwyktikpamitr (type "P"); Var propertyAccess = Expression.MakeMemberAccess (Expressions parameters, expression property); Var Ordrbiiakspi = expression. lambda (Proprtiaves , Expression Parameter); Finance Prinamakspi = Abhiwyktikcol (Taipf (query), "Order B", a new type [] {type, Abhiwyktiproprtikproprti type} items. Expression, expression. Coat (Krambiaiakspi)); return items. Analimebl (). Providers . Kriatti Krenti & lt; T & gt; (resultExp);}  

I runtime Can not change, but you can not just work around this? Ie

  Public IQueryable  All & lt; TValue & gt; (Expression & Lt; Func & lt; T, TValu & gt; & Gt; Sort) {EntityContext.Creatate & quot; T & gt; (EntityName). Eskenable & lt; T & gt; (). Order B & amp; T; T, TLL & gt; (Sort); }  

and

  IQueryable & lt; Blog & gt; All Sorted = _respirary.all (x = & gt; x.SomeProp);  

?


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -