1

次のクエリは、serverID で 2 つのテーブルを結合し、以下に示すように、ServerID とそれらに属するコンポーネントを返します。

リンク

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

共通コンポーネントの記録を削除して、上記の結果を取得する方法は? これは、<> not equal to を使用して SQL で実現できます。上記のコードでどのように達成できますか?

4

2 に答える 2

2

コンポーネントに制約を設定するだけです:

select new
{
   a.ServerID,                                
   Comp = g.Where(x => x.Name != "common component").Select(x => x.Name),                              
}
于 2013-06-20T13:48:19.527 に答える
1

プロジェクションでは、selectそれを除外するだけです:

Comp = g.Where(x => x.Name != "common component").Select(x => x.Name), 
于 2013-06-20T13:48:02.257 に答える