c# - Order and OrderProduct -
i seem having problem when handling order shopping cart. firstly have create instance of order(orderid,custid,...)....but in orderproduct how assign orderid (it set has identity specification in sql), because required foreign key in orderproduct in database.
public class order { string customerid; string shipping_firstname; string shipping_lastname; string shipping_address; string shipping_city; string payment_firstname; string payment_lastname; string payment_address; string payment_city; } orderproduct class,
public class orderproduct { string orderid; string productid; string quanity; }
try make objects represent things in real life. might sound little weird object named orderproduct doesn't represent in real life , bad design. after relationship between product , order. list<product> in class order? can fill list products , remove products easily. when interacting database make record in table orderproduct each item in list.
have @ idea:
public class product { int productid; string name; } public class order { int orderid; customer customer; list<product> products; datetime orderdate; } you seem mixing paradigms. aware doing object-oriented programming relational database. shouldn't mix 2 up. there is, example, no object represents table in database. object represents object in real world, , it's properties may stored in combination of tables. order made customer, has list of products on it, quantities, total price, etc. cannot store 1 object 1 record in database, know applying normalisation in relational db. 1 object results in several records in db.
often oop programmers make "data-layer" or "tier" in programs, "converts" oop relational before storing db.
Comments
Post a Comment