Entity framework 实体框架核心计数另一个表中的无关记录

Entity framework 实体框架核心计数另一个表中的无关记录,entity-framework,linq,asp.net-core,Entity Framework,Linq,Asp.net Core,我需要计算一下tableA中有多少记录不在tableA中,如何使用LINQ实现这一点 使用SQL,我按照以下方式执行 select count(*) as total from produtoitemgrade g where g.id not in (select idprodutograde from produtoestoque where idProduto = 12) and g.idProduto = 12 到目前为止,我的linq代码 var temp = (from a in

我需要计算一下tableA中有多少记录不在tableA中,如何使用LINQ实现这一点

使用SQL,我按照以下方式执行

select count(*) as total from produtoitemgrade g
where g.id not in (select idprodutograde from produtoestoque where idProduto = 12)
and g.idProduto = 12
到目前为止,我的linq代码

 var temp = (from a in Produtoitemgrades
              join b in Produtoestoques on a.IdUnico equals b.IdUnicoGrade into g1
              where g1.Count(y => y.IdProduto == 12)>0 && !g1.Any()
              select a).ToList();
我试着效仿这个例子

但是运行时会发生错误,我如何才能做到这一点?
谢谢

如果希望具有相同的SQL执行计划,则查询应如下所示:

var查询=
来自Produtoitemgrades中的
哪里其中(b=>a.IdUnico==b.IdUnicoGrade&&b.idProduto==12)。任意()
&&a.idProduto==12
选择一个;
var result=query.Count();