How can I combine multiple refactored Select expressions in Linq (to EF or SQL)? -


say have view model:

public class serieslinkviewmodel {     public static expression<func<series, serieslinkviewmodel>> fromseries =         s => new serieslinkviewmodel         {             name = s.name,             slug = s.slug,         };      public string name { get; set; }     public string slug { get; set; } } 

i stuck projection function in there convenience, can like:

var links = dc.series.select(serieslinkviewmodel.fromseries); 

awesome. do if wanted add query? wanted pull description column table. normally, select new { } , put description in there, can't quite because can put 1 projection function in `.select() .

i hoping this:

q = s in dc.series     select new     {         series = serieslinkviewmodel.fromseries.compile()(s),         description = s.description     }; 

but exception:

system.invalidcastexception: unable cast object of type 'system.linq.expressions.fieldexpression' type 'system.linq.expressions.lambdaexpression'.

or @ least have these queries done in 1 round trip somehow? know transactionscope works making changes, don't think causes queries done @ once.

solved linqkit:

var fs = serieslinkviewmodel.fromseries; //needs local reason q = s in dc.series.asexpandable() //enables linqkit magic     select new     {         series = fs.invoke(s), //and voila!         description = s.description     }; 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -