这是我第一次进入LINQ。 我仍然不得不围绕结果部分,但我似乎无法得到任何结果。LINQ查询不显示结果 - 左加入WHERE子句
var institutions = from lots in lotsdb.NEWinstitution
join webs in webbitdb.tblinstitution
on lots.institutionid equals webs.dispenseinstid into newinsts
from webs2 in newinsts.DefaultIfEmpty()
where webs2 == null
select new
{
instid = lots.institutionid,
instname = lots.institutionname
};
foreach(var instfound in institutions)
{
MessageBox.Show(instfound.instid.ToString() + " " + instfound.instname.ToString());
}
我在使用DATASources列表中的Visual Studio创建的数据集。
下面是我原来的SQL字符串,我有“尝试”,以适应LINQ
string strgetloc = @"
SELECT NEWinstitution.institutionid, NEWinstitution.institutionname
FROM NEWinstitution
LEFT JOIN tblinstitution
ON NEWinstitution.institutionid = tblinstitution.dispenseinstid
WHERE (((tblinstitution.institutionid) Is Null));"
你真的只需要空的吗? '在哪里webs2 == null' –
我一直canabalising LINQ的例子..我猜这是不正确的。 我想lotsdb.NEWinstitution.institutionid WHERE webbitdb.tblinstitution.institutionid IS NULL –
您确定此查询返回结果吗?你有没有试过在SQL Server中运行类似的东西? – gh9