且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

LINQ语句的Where子句中的子查询

更新时间:2021-06-29 04:05:22

我认为一个简单的联接就可以完成这项工作.它将滤除没有相对应用"的支票":

I think a simple join would do the job. It will filter out the 'cheques' that have no relative 'app':

  var _entitylist = 
    from cheque in context.postDatedCheques
    join app in context.applications on cheque.appSancAdvice.application equals app
    select cheque;

使用 .Contains(...)的解决方案将转换为SQL IN 语句.这将是非常低效的.Linq join 转换为SQL INNER JOIN ,如果您的数据库架构经过精心修剪(FK,索引),这将非常有效

Solutions using a .Contains(...) will be translated into a SQL IN statement. Which will be very inefficient. Linq join is translated into SQL INNER JOIN which is very efficient if your DB schema is well trimmed (FKs, index)