c# - Dynamically loading SQL tables in Entity Framework -


i need dynamically access sql tables using entity framework. here's pseudo code:

var account = db.accounts.singleordefault(x => x.id == 12345);

which return me account object , contains fields called "prefix", "campaign id" , further information accounts stored in separate sql tables naming convention of prefix_campaignid_main.

the tables have same fields thinking of creating new entity isn't mapped anywhere , dynamically loading it, so:

var sta01_main = new myaccount(); // "un-mapped" entity

db.loadtable('sta01_main').loadinto(sta01_main);

i can sta01_main account: sta01_main.accountid.

so question is: how access these tables using entity framework?

i don't think ef has loadtable , loadinto method, objectontext.executestorequery might you're looking for:

http://msdn.microsoft.com/en-us/library/dd487208.aspx

this should let execute arbitrary query against database, , map results arbitrary type specify (even if it's not otherwise mapped in ef).

it goes without saying responsible putting query supplied necessary columns mapping destination type, , adjusting said query when type changes.

here's further discussion concerning usage

http://social.msdn.microsoft.com/forums/en-us/adonetefx/thread/44cf5582-63f8-4f81-8029-7b43469c028d/

have considered mapping of these tables (with identical columns) inheritance relationship in ef, , querying them

db.basetypes.oftype<specifictype>().where(/*.....*/);


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -