Skip to main content
 首页 » 编程设计

c#之如何将以下 SQL 转换为 Linq

2024年02月23日12duanxz

我正在使用 IQueryable<T>界面。

如何将下面的sql语句翻译成IQueryable ?

select * from customer 
where joindate > DateTime.Now and 
      (customertype = 'system' or customerstatus = 'active') and 
      customerlocation = 'europe' 

请您参考如下方法:

像这样:

    var result = from record in context.customer  
    where record.joindate > DateTime.Now &&  
        (record.customertype == "system" || record.customerstatus == "active") &&  
        record.customerlocation == "europe" 
    select record 

有一个很好的工具,Linqer,可以帮助您将 SQL 查询转换为 LINQ。当然,对于这种简单的情况,它有点矫枉过正,但如果您更熟悉 SQL,当然可以考虑将其用于繁重的查询。

你可以在这里找到它 LINQER .