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

c# - Farseer ContactListener is not working -

Automatically create pages in phpfox -

database - one php page with different contents and urls -