c# - Load data by type using Entity Framework -


i want do

list<isomeinterface> result = new list<isomeinterface>(); foreach(type type in someassem.gettypes.isassignablefrom(isomeinterface))         result.addrange(loadtype(type)); 

is possible load entities type? need load them, no more operation needed. prefer using code first , tpt or tpc hierarchy solution.

i have seen generic repositories patterns, of them need pass class. using entity framework 6 , .net 4.5.

you can use dbset.set() method accepting type argument:

public ienumerable<t> loadtype<t>(type type) {     return context.set(type).cast<t>(); } 

then:

result.addrange(loadtype<isomeinterface>(type)); 

see msdn


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -