如何编写LINQ to SQL等效项:
INSERT INTO Table1 (field1, field2, field3)
SELECT field1, field2, field3
FROM Table2
WHERE (field1= @field1)
谢谢
最佳答案
由于您没有返回任何结果,因此只需使用低级DataContext.ExecuteCommand()
方法:
using (MyDataContext dc = new MyDataContext())
{
dc.ExecuteCommand(@"
INSERT INTO Table1 (field1, field2, field3)
SELECT field1, field2, field3
FROM Table2
WHERE (field1= {0})
",
field1);
}
关于.net - 如何在LINQ中执行 “INSERT INTO table1 (…) SELECT (…) FROM table2”?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1416858/