-------------
Products |
-------------
id |
name |
price |
image |
-------------
-------------
Sizes |
-------------
id |
name |
quantity |
id_product |
-------------
表Sizes
では、製品のサイズごとに異なるサイズと数量を保持しています。たとえば、製品にジーンズをSizes
1 組入れていますが、表ではサイズ.名前 M で数量 20、サイズ.名前 XL で数量 30 などにしています。
私のプロジェクトでは、すべてのデータを表示したいとき、私はこのように sth を持っています。
id |name |price | size_name | quantity |
-----------------------------------------------------------
1 jeans 100 M 20
1 jeans 100 XL 30
1 jeans 100 S 45
等
私が表示したいのは:
id |name |price | S | M | XL |
-------------------------------------------------
1 jeans 1000 45 20 30
そのため、ピボットを使用する必要があることを読みましたが、開始方法と次に何をすべきかわかりません。これが私のコードの一部です:
var query = from product in context.Products
join size in context.Sizes on product.ID equals r.Product.ID
//what's the next step?
select new { };
dataGridView1.DataSource = query.ToList();
===================================
編集
====================================
今、私はこのようなsthを持っています
まあ{id, name}
キーではありませんが、別の問題があるようです。
var q = (from p in context.Produkty
join r in context.Rozmiary
on p.ID equals r.Produkt.ID
into sizes
select new
{
S = sizes.Where(x => x.Nazwa == NazwaRozmiaru.S).Sum() ?? 0
});
dataGridView1.DataSource = q.ToList();
これをくれる
Error 2 'System.Collections.Generic.IEnumerable<Magazynier.Model.Rozmiary>' does not contain a definition for 'Sum' and the best extension method overload 'System.Linq.ParallelEnumerable.Sum(System.Linq.ParallelQuery<decimal?>)' has some invalid arguments C:\Users\Piotr\Downloads\Magazynier (7)\Magazynier\Magazynier\Form1.cs 45 34 Magazynier
この
Error 3 Instance argument: cannot convert from 'System.Collections.Generic.IEnumerable<Magazynier.Model.Rozmiary>' to 'System.Linq.ParallelQuery<decimal?>' C:\Users\Piotr\Downloads\Magazynier (7)\Magazynier\Magazynier\Form1.cs 45 34 Magazynier
この
Error 4 The type arguments for method 'System.Linq.Enumerable.ToList<TSource>(System.Collections.Generic.IEnumerable<TSource>)' cannot be inferred from the usage. Try specifying the type arguments explicitly. C:\Users\Piotr\Downloads\Magazynier (7)\Magazynier\Magazynier\Form1.cs 47 43 Magazynier
私のSizes(別名Rozmiary)はc#で次のようになります
public enum NazwaRozmiaru
{
S,
M,
L,
}
public class Rozmiary : KlasaBazowa
{
public Produkty Produkt { get; set; }
public NazwaRozmiaru Nazwa { get; set; }
public int Ilosc { get; set; }
}