Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linq join get null rows过滤器,带where_Linq_Join_Null - Fatal编程技术网

Linq join get null rows过滤器,带where

Linq join get null rows过滤器,带where,linq,join,null,Linq,Join,Null,我有三张桌子。存储、存储报告和报告 Store table StoreId Storename. Report table ReportId ReportName StoreReport table StoreId ReportId 我想得到所有没有填写具体报告的商店。 到目前为止,我有这个,但它也计算那些与其他报告有关的人 var reports = from u in db.tblStores join sr in db.t

我有三张桌子。存储、存储报告和报告

Store table
StoreId 
Storename.

Report table
ReportId
ReportName

StoreReport table
StoreId
ReportId
我想得到所有没有填写具体报告的商店。 到目前为止,我有这个,但它也计算那些与其他报告有关的人

var reports = from u in db.tblStores
                              join sr in db.tblStoreReports.Where(a => a.ReportId != reportId && !a.Deleted)
                        on u.StoreId equals sr.StoreId into g
                    where !g.Any()
                    select u;

您可以使用
!。任何
,以确保它没有带有特定
id的
报告

,不是更简单吗?您可以在不使用联接的情况下使用
Where

var reports = from u in db.tblStores
              where !db.tblStoreReports.Any(sr => sr.StoreId == u.StoreId 
                                               && sr.ReportId == reportId 
                                               && !sr.Deleted)
              select u;

嗯,这将返回表存储中的所有行。包括两个有报告的人。这可能是一种多对多的关系吗?这两种关系都起作用了。我意识到错误在输入数据中。与此相同。它返回表存储中的所有行。包括两个有报告的人。这可能是一种多对多关系吗?你能提供一些样本数据/对象集合吗?这两种方法都有效。我意识到错误在输入数据中。
var reports = from u in db.tblStores
              where !db.tblStoreReports.Any(sr => sr.StoreId == u.StoreId 
                                               && sr.ReportId == reportId 
                                               && !sr.Deleted)
              select u;