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

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -