【解決方法】あらゆる種類の製品に関連する個人情報を取得するリポジトリを作成する方法


Hello, good time. In asp net mvc, how can we write a repository that when the user clicks on a product... get the private information of each type of product with the common information of the products...
For example, TV...screen size...
I have defined a separate private information table for some of the products...
And I don't know how to show the information of the private and common table of products to the user in the repository

私が試したこと:

I could create a table for the product characteristics... and put the product ID in this table once for each characteristic... which was not an optimal method.

解決策 1

「特定の製品に関連する未知の数のアイテムをデータベースに保存する方法」について話していると仮定すると、最良の方法は間違いなく、ID への外部キー参照を使用して、アイテムを別のテーブルに保存することです。製品そのもの: ほとんどすべてのものに対して、私たちはこの方法で取り組んでいます。
たとえば、請求書を考えてみましょう。「一回限りの品目」を含むテーブルがあります。

請求書
ID
CustomerID   - foreign key to Customers table
Date
Total

次に、注文した商品ごとに、別のテーブルに別の行が表示されます。

請求書明細
ID
InvoiceID  - foreign key to Invoices table
Quantity
ProductID  - foreign key to the Products table
PerItemValue

その後、SQL JOIN を使用して特定の会社の請求書を組み立てることができます。

SQL
SELECT L.Quantity, 
       L.PerItemValue, 
       P.Description,
       L.Quantity * L.PerItemValue AS LineValue
FROM Invoices I
JOIN InvoiceLines L ON L.InvoiceID = I.ID
JOIN Products P ON l.ProductID = P.ID

そして、次のような一連の行が返されます。

結果
Quantity   PerItemValue  Description          LineValue
       6          19.99  Expensive plates        119.94
       2           9.99  Saucepan                 19.98
       1         199.99  Small TV                199.99

そうすれば、製品に関連付ける属性の数や属性のタイプは問題になりません。

属性タイプも別のテーブルに置き、そこに適切な外部キーも追加します。

わかる?

コメント

タイトルとURLをコピーしました