Пример:
- Company1_Entities
- Company2_Entities
- Company3_Entities
All_Bills_Entities
Поскольку количество компаний будет расти, мне нужно сделать это динамичным. Я думал о чем-то таком:
Dictionary lstDB = new Dictionary();
// I'm supposed to retrieve these db names from a table, but now I'm just testing
lstDB.Add("00439837", new DbContext("Company1_Entities"));
lstDB.Add("00439832", new DbContext("Company2_Entities"));
lstDB.Add("00439839", new DbContext("Company3_Entities"));
using (All_Bills_Entities main_db = new All_Bills_Entities())
{
foreach(var dataBaseInfo in lstDB)
{
DbContext currentDB = dataBaseInfo.Value;
foreach (var record in currentDB.bill.ToList()) // this does not compile, there is no bill table found here
{
if(record.merchant == dataBaseInfo.Key /* && other Conditions */)
{
main_db.bill.Add(record)
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/504 ... -correctly
Мобильная версия