gpt4 book ai didi

.net - 将 LINQ 翻译成 sql 语句

转载 作者:行者123 更新时间:2023-12-04 00:12:25 28 4
gpt4 key购买 nike

我想将 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;

关于.net - 将 LINQ 翻译成 sql 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/550826/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com