c# - Dynamically query entity framework with linq -


i need function key-value pair of id , description entity model populating fields on user control , i'd find way make dynamic in order avoid repeating code.

my pseudo-code:

public list<object> getdata(string modelname, string modelid, string modeldescription) {     using(dbentities context = new dbentities())     {         return (from d in context.modelname                 select new {                              id=d.modelid,                             description = d.modeldescription                            }                ).tolist<object>();     } } 

a possible partial solution this, table needs dynamically defined too.

in context have similar to

public dbset<myentity> thepropertyname {get; set;} 

when call function modelname = "thepropertyname"

so retrieve dbset via reflection run tolist on it. use foreach on entities , via reflection retrieve properties modelid , modeldescription.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -