2011-12-07 6 views
0
public static IList<string> GetAttribute_1(ModelContainer context, long productcatid) 
{ 
    var query = from product in context.Products 
       where product.ProductCategory_Id == productcatid 
       select product.Attribute_1; 

    return query.ToList(); 
} 

どのように製品ごとにグループ化しますか.Attribute_1?LINQを使用してIList <T>をグループ化するには?

答えて

1

グループは、LINQ演算子によってグループを使用することによって行うことができます。

構文は次のようになります。あなたがグループ化のためのLINQのサンプルを見つけることができます

var query = from product in context.Products 
         where product.ProductCategory_Id == productcatid 
         group product by prodyct.Attribute_1 into g 
         select new { Attribute_1 = g.Key, Products = g }; 

Here

しかし、すべてのunqiue Attribute_1プロパティがあなたの関数から返されるとしますか?

次に、Distinct演算子を使用できます。これは、一意の値だけを含むようにAttribute_1文字列のリストを補完します。

+0

はい、ありがとうございました。私が探していたものです – Beginner

1
from product in context.Products 
where product.ProductCategory_Id == productcatid 
group product by product.Attribute_1 into g 
select g; 
関連する問題