本文介绍了怎么办" INSERT INTO表1(...)选择(...)FROM表2"在LINQ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样写一个LINQ到SQL等价的:

How do I write a LINQ to SQL equivalent of:

INSERT INTO Table1 (field1, field2, field3)
SELECT field1, field2, field3
FROM Table2
WHERE (field1= @field1)

感谢

推荐答案

既然你不返回任何结果,只使用低级别的 DataContext.ExecuteCommand()方法:

Since you aren't returning any results, just use the low-level DataContext.ExecuteCommand() method:

using (MyDataContext dc = new MyDataContext())
{
    dc.ExecuteCommand(@"
        INSERT INTO Table1 (field1, field2, field3)
        SELECT field1, field2, field3
        FROM Table2
        WHERE (field1= {0})
        ",
        field1);
}

这篇关于怎么办" INSERT INTO表1(...)选择(...)FROM表2"在LINQ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 22:44