c# - How do I abstract out the select in this Entity Framework IQueryable query? -


i have following entity framework queries:

var items1 = items.select(x=> x.prop1)                   .select(...).orderby(..).toarray();  var items2 = items.select(x=> x.prop2)                   .select(...).orderby(..).toarray();  var items3 = items.select(x=> x.prop3)                   .select(...).orderby(..).toarray(); 

as can see repeated code.

the following .select(...).orderby(..).toarray(); same.

i can't seem find way extract first select

something like,

var temp = select(x=> x.prop1); 

i want turn loop using reflection, above statement gives me compile error.

the application on .net 4 don't have access new may have come solve problem.

just move function:

resulttype[] execute(iqueryable<typeofprops> query) {      return query.select(...).orderby(..).toarray() } 

if don't want create separate function - create anonymous:

func<iqueryable<typeofprops>,resulttype[]>> execute = (query) =>      query.select(...).orderby(..).toarray(); var items1 = execute(items.select(x=> x.prop1)); var items2 = execute(items.select(x=> x.prop2)); var items3 = execute(items.select(x=> x.prop3)) 

Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -