我有一個實(shí)體框架的 6.0 數(shù)據(jù)庫第一個上下文的列表,名稱不同。它們都包含一個名為“bill”的表。我需要檢查每個數(shù)據(jù)庫的賬單表,并根據(jù)條件將信息添加到一個新數(shù)據(jù)庫中。例子 :Company1_EntitiesCompany2_EntitiesCompany3_Entities這 3 個數(shù)據(jù)庫包含賬單表。我需要將這些賬單有條件地存儲到:All_Bills_Entities隨著公司數(shù)量的增長,我需要讓這個動態(tài)。我在想這樣的事情:Dictionary<string, DbContext> lstDB = new Dictionary<string, DbContext>();// I'm supposed to retrieve these db names from a table, but now i'm just testinglstDB.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) } } }}
- 1 回答
- 0 關(guān)注
- 175 瀏覽
添加回答
舉報(bào)
0/150
提交
取消