2

配列のように、コンマで区切られたテキスト値の文字列があると仮定します。

var excludelist ="apples,oranges,grapes,pears";

除外リストの値は、データベース内のテーブルへのクエリから取得される場合があります。

Fruitという名前のフィールドに除外リストの項目が含まれている行を除くすべての行を返すクエリを想定します。

var qry = from s in context.Groceries.Where(s => s.Fruit(here is where we need to exclude the items??) join u in context.Users on s.Owner equals u.User_ID

誰かがSQL回答へのサンプルリンクを提供できますか?

4

2 に答える 2

0

私はこのように解決しました:

除外したい果物の名前を含むデータベーステーブルがあり、リストを作成しました(IListは明らかに機能しません)。

List<string> excludedfruit = context.ExcludedFruit.Select(x => x.ExcludedFruitName).ToList();

次に、次の Linq to SQL クエリを使用しました (部分的に表示)。

        var qry = from s in context.Groceries
                .Where(s => !excludedfruit.Contains(s.Fruit))
于 2012-05-28T18:32:20.850 に答える
0

試しましたExceptか?

var qry = from s in context.Groceries.Except(excludelist)...

SQL へのリンクにはCONTAINS(and!CONTAINS)があります

where !excludelist.Contains(i)
        select i;
于 2012-05-28T00:33:29.077 に答える