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不存在多个表_Linq - Fatal编程技术网

Linq不存在多个表

Linq不存在多个表,linq,Linq,我想做一个LINQ不存在于多个表上的查询 谷歌上所有的例子都是处理两张表,我正在处理三张表,所以作为LINQ的新手,我很难正确地引用它们 首先,我尝试了这个LINQ查询 var nocertificates = ( from x in rmdb.t_certificates from ce in rmdb.t_user_certificates from u in rmdb.t_users where u.id == ce.uid && ce.value !=

我想做一个LINQ不存在于多个表上的查询

谷歌上所有的例子都是处理两张表,我正在处理三张表,所以作为LINQ的新手,我很难正确地引用它们

首先,我尝试了这个LINQ查询

  var nocertificates = (
  from x in rmdb.t_certificates
  from ce in rmdb.t_user_certificates
  from u in rmdb.t_users
  where u.id == ce.uid && ce.value != x.id
  select x).AsEnumerable().Select(x => new ViewModelCheckBox()
      {
         Value = x.id.ToString(),
         Name = x.name,
         Checked = false
      });
我用了三次丑陋的,因为我不太擅长创建类型加入。 但这给出了错误的结果,我意识到我必须选择一个不存在的

因此,我在T-SQL中构建了一个新的查询

这就是它工作的SQL查询

select distinct * from t_certificates tc
where NOT EXISTS
(
select distinct * from t_users tu, t_user_certificates tuc
WHERE tu.email = 'user@email.com'
and tu.id = tuc.[uid]
and tuc.value = tc.id
)
在LINQ我该怎么做?

这就是问题所在,我将为此奖励我的答案

但是

当我们这样做的时候。。。我对答案很好奇。。是否可以执行一个LINQ查询,返回一个Ienumerable,其中包含存在和不存在的Ienumerable,从而生成一个对象,该对象将在选中的属性上保存不同的值
EXISTS->checked=true
NOT EXISTS->checked=false

这就是我创建对象的方式

   .Select(x => new ViewModelCheckBox()
      {
         Value = x.id.ToString(),
         Name = x.name,
         Checked = this should be different based on exists or not
      });

LINQ答案应该是这样的(未经测试):


LINQ答案应该是这样的(未经测试):


这就是我最后使用的

var query = (from tc in rmdb.t_certificates 
             where !(
                     from tu in rmdb.t_users
                     from tuc in rmdb.t_user_certificates
                     where tu.email == username
                     && tu.id == tuc.uid
                     && tuc.value == tc.id select tc).AsEnumerable().Any() 
                     select new ViewModelCheckBox()
                                { Checked = false,
                                  intconverter = tc.id,
                                  Name = tc.name
                                });

这就是我最后使用的

var query = (from tc in rmdb.t_certificates 
             where !(
                     from tu in rmdb.t_users
                     from tuc in rmdb.t_user_certificates
                     where tu.email == username
                     && tu.id == tuc.uid
                     && tuc.value == tc.id select tc).AsEnumerable().Any() 
                     select new ViewModelCheckBox()
                                { Checked = false,
                                  intconverter = tc.id,
                                  Name = tc.name
                                });

对于第二个问题:从概念上讲,这只是一个带有WHERE子句的左外部联接,该子句仅从右侧表中选择字段不可为NULL的记录。对于第二个问题:从概念上讲,这只是一个带有WHERE子句的左外部联接,该子句仅从右侧表中选择字段不可为NULL的记录为空。嗯,有些地方出错了,表格不一致。。。我为linq和SQL使用了其他名称:(我得到了错误的作用域。)嗯,有些地方出错了,表不一致……我为linq和SQL使用了其他名称:(我得到了错误的作用域。)。。