Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.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

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
C# 如何使用SQL语法和<;重写此LINQ查询>;?_C#_Linq - Fatal编程技术网

C# 如何使用SQL语法和<;重写此LINQ查询>;?

C# 如何使用SQL语法和<;重写此LINQ查询>;?,c#,linq,C#,Linq,下面的查询连接serverID上的两个表,并返回serverID和属于它们的组件,如下所示 LINQ var header = from a in this.db.Servers where a.ServerID.Contains(match) join b in this.db.Components on a.ServerID equals b.ServerID into g

下面的查询连接serverID上的两个表,并返回serverID和属于它们的组件,如下所示

LINQ

var header  = from a in this.db.Servers
               where a.ServerID.Contains(match)
               join b in this.db.Components
               on a.ServerID equals b.ServerID into g
               select new
               {
               a.ServerID,                                
               Comp = g.Select(x => x.Name),                              
               };
输出

Server X
common component
component 1x
component 2x
component 3x
Server Y
common component
component 1y
component 2y
component 3y
Server Z
common component
component 1z
component 2z
component 3z

如何检索上述结果,删除公共组件的记录?这可以在SQL中使用not等于来实现。如何使用上述代码实现它?

在您的
选择
投影中,只需将其过滤掉:

Comp = g.Where(x => x.Name != "common component").Select(x => x.Name), 

只需在组件上设置一个约束:

select new
{
   a.ServerID,                                
   Comp = g.Where(x => x.Name != "common component").Select(x => x.Name),                              
}

所以您只想从结果集中排除
公共组件
?@demo\u用户检查,您肯定会知道。可能的重复