C# Accessing an Entity Framework Class with only Type Information -


ok, question tough me explain new generics , many of high level features of c#. trying write method using generic type used both instantiate new object of type , use type information access correct class in entity framework 5.0 dbcontext. have not compile believe code better explain problem, wording vague explain trying do.

code

public void addnewrecord<t>() t : new()   {         t record = new t();       _context.t.add(record);  //here problem t tbl_x     _bindsource.datasource = _context.t.local.tobindinglist(); //same goes here   } 

how can use t access class in dbcntext?
not sure possible. appreciate guys/gals can offer.

you want this:

_context.set<t>().add(record); _bindingsource.datasource = _context.set<t>().local.tobindinglist(); 

i notice context class member. careful using dbcontext way, dbcontexts designed short lived, , slower , slower , user more , more memory without giving if keep around life of program.

dbcontext not real memory management, or pruning of caches because expects destroyed relatively quickly.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -