加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

.net – 将LINQ翻译成sql语句

发布时间:2020-12-12 16:44:03 所属栏目:MsSql教程 来源:网络整理
导读:我想将LINQ表达式树翻译成SQL语句,我不想??为此编写自己的代码. 例: var query = from c in Customerswhere c.Country == "UK" c.City == "London"select c); 至 SELECT ... FROM Customers AS c WHERE c.Country = "UK" AND c.City = "London" 我知道DataCo
我想将LINQ表达式树翻译成SQL语句,我不想??为此编写自己的代码.

例:

var query = from c in Customers
where c.Country == "UK" &&
      c.City == "London"
select c);

SELECT ... FROM Customers AS c WHERE c.Country = "UK" AND c.City = "London"

我知道DataContext.Log,但我想使用:

query.ToSqlStatementString()

解决方法

CustomDataContext dc = new CustomDataContext();
IQueryable<Customer> query =
  from c in dc.Customer
  where c.Country == "UK"
  select c;
//
string command = dc.GetCommand(query).CommandText;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读