D
D
Dmitry Gavrilenko2016-11-08 11:59:36
.NET
Dmitry Gavrilenko, 2016-11-08 11:59:36

How to design such Code First?

Shalom. Cash register simulation.
There are 3 classes.
Check, Product, ProductItem.
Check - is a check; contains all information about purchases. Inside the ProductItem collection .
ProductItem - Connecting entity. It has a Product and a Count property.
Product - Contains product information.
Interactive
61def152958044a3bba6903dba3ccf75.png
There is a one-way communication, from top to bottom. And I don't need feedback.
How to describe it in CodeFirst, what would be stored in the norm base?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Zhidkov, 2016-11-08
@VigVam

If I understood you correctly, then this is many-to-many (i.e., there can be several products in a receipt, and one product in several receipts) .... If so, then it should look something like this ....

public class Check{
    public int Id {get;set;}
    public ICollection<ProductItem> ProductItem {get;set;}
}
public class Product{
    public int Id {get;set;}
    public ICollection<ProductItem> ProductItem {get;set;}
}
public class ProductItem{
    public int ProductId {get;set;}
    public Product Product {get;set;}

   public int CheckId {get;set;}
   public Check Check {get;set;}

   public int Count {get;set;}
}

See here for details - metanit.com/sharp/mvc5/5.9.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question