等同于代码优先的实体框架中的代码
INSERT INTO TableA (a,b)
SELECT a,b
FROM TableB
WHERE a=10
答案 0 :(得分:0)
我相信您尝试根据条件从TableB
中选择几列,然后将所有这些对象添加到TableA
,可以执行以下操作:
//Create list of TableA objects after selecting and projecting from TableB
var list = db.TableB.Where(t => t.a == 10)
.Select(r => new TableA() { A = r.a, B = r.b })
.ToList();
//Add those items to TableA through DataContext
foreach (var item in list)
db.TableA.AddObject(item);
//Call Save
db.SaveChanges();