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
Post a Comment