c# - Entity Framework Execute Query on Multiple Servers -


i developing first c# web app , needs import data multiple servers on demand.

i have server names stored in table (dataserver). need connect each server , run query, results of want add data model.

this have in repository

public void scanserver(int serverkey)     {         var servername =  findbykey(serverkey).servername;         var sqlquery = "select name ,description mytbl";          context.database.sqlquery<names>(sqlquery);     } 

i know using context incorrect, i'm hoping replace connection string held in dataserver table.

the results need added names datamodel.

am on right track this?

you should able open connection using connection string thus:

foreach(string connectionstring in servers) {     using (var context = new dbcontext(connectionstring))     {       //query code     } } 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -