1

等效于代码优先中实体框架中的以下代码

INSERT INTO TableA (a,b)
SELECT a,b
FROM TableB
WHERE a=10
4

1 回答 1

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();
于 2013-04-16T05:30:06.277 回答