Join or the nomemclature for join using EF in c#
-
I have this flattened database design, and in checkout, I need to get the total weight of the cart items. So I did a method call to the shopping cart and I have the items in a List, But I need to get the Product Dimensions in another table that I did not join, because I used the database table to store the data in and I don't have a place to store the dimensions. I'm not sure if I should rewrite this again, or if there is a quick fast way to get the dimensions. I really don't want to make another model to do this.
// Build a list of cart items
if (context.SHOPPING_CART.Any(m => m.customer_accountName == aN))
sCs = context.SHOPPING_CART.Where(m => m.customer_ID == cID).ToList();
if (sCs != null)
{
orderTotal = sCs.Sum(m => m.item_Price_Value * m.item_Qty);
orderCost = sCs.Sum(m => m.item_Cost_Value * m.item_Qty);
orderProfit = orderTotal - orderCost;
orderWeight = "was hoping for quick method here"}
PRODUCT_DIMENSIONS Weight_Gravity is the field that I want to join so I can sum.
Globalism is Socialism on a planetary scale.
-
I have this flattened database design, and in checkout, I need to get the total weight of the cart items. So I did a method call to the shopping cart and I have the items in a List, But I need to get the Product Dimensions in another table that I did not join, because I used the database table to store the data in and I don't have a place to store the dimensions. I'm not sure if I should rewrite this again, or if there is a quick fast way to get the dimensions. I really don't want to make another model to do this.
// Build a list of cart items
if (context.SHOPPING_CART.Any(m => m.customer_accountName == aN))
sCs = context.SHOPPING_CART.Where(m => m.customer_ID == cID).ToList();
if (sCs != null)
{
orderTotal = sCs.Sum(m => m.item_Price_Value * m.item_Qty);
orderCost = sCs.Sum(m => m.item_Cost_Value * m.item_Qty);
orderProfit = orderTotal - orderCost;
orderWeight = "was hoping for quick method here"}
PRODUCT_DIMENSIONS Weight_Gravity is the field that I want to join so I can sum.
Globalism is Socialism on a planetary scale.
What's the structure of the database / EF model? And are you really only going to allow each customer to have a single cart? Or are you going to delete the cart once it's processed?
jkirkerx wrote:
if (context.SHOPPING_CART.Any(m => m.customer_accountName == aN)) sCs = context.SHOPPING_CART.Where(m => m.customer_ID == cID).ToList();
Not sure what purpose that "if" serves? The condition doesn't match the following
Where
clause; and even if it did, it would only slow down the performance of your code.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
What's the structure of the database / EF model? And are you really only going to allow each customer to have a single cart? Or are you going to delete the cart once it's processed?
jkirkerx wrote:
if (context.SHOPPING_CART.Any(m => m.customer_accountName == aN)) sCs = context.SHOPPING_CART.Where(m => m.customer_ID == cID).ToList();
Not sure what purpose that "if" serves? The condition doesn't match the following
Where
clause; and even if it did, it would only slow down the performance of your code.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
On the design of the cart, I decided to use a field called "Account Name". At first when an account does not exist, I use the session number in the "Account Name" field. Then I try to lure the shopper into creating an account or upon checkout, they create an account. Once the account is created, I write a cookie with their info and swap the session number with the account name. Now the stage is set for each time the cart page is loaded, I can load their items automatically, from any device they use such as phone or desktop. Upon PlaceOrder, the Linq I'm asking about, the cart content will be copied to another table and the shopping cart will be deleted. This is the program at it's current state, [Project Indigo] - test drive store. There's a table called "Product_Info" that contains the master product information, In which "Product_Dimensions" can be joined to.
[Table("dbo.SHOPPING_CART")]
public class SHOPPING_CART
{
[Key()]
[Column(Order = 1)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int cart_ID { get; set; }
[Required]
public int customer_ID { get; set; }
[Required]
[MaxLength(80)]
public string customer_accountName { get; set; }
[Required]
public DateTime timeStamp { get; set; }
[Required]
[MaxLength(80)]
public string item_Type { get; set; }
[Required]
public int item_ID { get; set; }
[Required]
public int item_Qty { get; set; }
public bool item_Taxable { get; set; }
[MaxLength(80)]
public string item_SKU { get; set; }
[MaxLength(160)]
public string item_Description_Title { get; set; }
[Required]
public decimal item_Cost_Value { get; set; }
public decimal item_RollCharge_Value { get; set; }
[Required]
public decimal item_Price_Value { get; set; }
[Required]
public decimal item_Total_Value { get; set; }
public int item_Avatar_ID { get; set; }
public byte[] item_Avatar_Data { get; set; }
[MaxLength(210)]
public string item_Avatar_Url { get; set; }
[MaxLength(10)]
public string type_Currency { get; set; }
[MaxLength(10)]
public string type_Weight { get; set; }
[MaxLength(80)]
public str -
What's the structure of the database / EF model? And are you really only going to allow each customer to have a single cart? Or are you going to delete the cart once it's processed?
jkirkerx wrote:
if (context.SHOPPING_CART.Any(m => m.customer_accountName == aN)) sCs = context.SHOPPING_CART.Where(m => m.customer_ID == cID).ToList();
Not sure what purpose that "if" serves? The condition doesn't match the following
Where
clause; and even if it did, it would only slow down the performance of your code.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
I think I'm going to throw that code in the trash and start again with a model to populate instead; split up the function into a load, calculate and then write.
Globalism is Socialism on a planetary scale.
I'd be inclined to normalize that table a lot more. You'd probably want something more like:
- Products - SKU, type, taxable, prices, weights, brand, department, vendor, etc.
- Customers - ID, account name, etc.
- Carts - ID, customer ID, etc.
- Items - ID, cart ID, product ID, quantity, price
Depending on your design, it might make sense to duplicate the product data on the lines for a processed cart. But "in-progress" carts should be referring back to the master product list.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
I'd be inclined to normalize that table a lot more. You'd probably want something more like:
- Products - SKU, type, taxable, prices, weights, brand, department, vendor, etc.
- Customers - ID, account name, etc.
- Carts - ID, customer ID, etc.
- Items - ID, cart ID, product ID, quantity, price
Depending on your design, it might make sense to duplicate the product data on the lines for a processed cart. But "in-progress" carts should be referring back to the master product list.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
I'd be inclined to normalize that table a lot more. You'd probably want something more like:
- Products - SKU, type, taxable, prices, weights, brand, department, vendor, etc.
- Customers - ID, account name, etc.
- Carts - ID, customer ID, etc.
- Items - ID, cart ID, product ID, quantity, price
Depending on your design, it might make sense to duplicate the product data on the lines for a processed cart. But "in-progress" carts should be referring back to the master product list.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
I shorted it down to this, and will just do a join to the master product table. Would you include the price or leave that out as well?
public class SHOPPING_CART
{
[Key()]
[Column(Order = 1)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int cart_ID { get; set; }\[Required\] public int customer\_ID { get; set; } \[Required\] \[MaxLength(80)\] public string customer\_accountName { get; set; } \[Required\] public DateTime timeStamp { get; set; } \[Required\] \[MaxLength(80)\] public string item\_Type { get; set; } \[Required\] public int item\_ID { get; set; } \[Required\] public int item\_Qty { get; set; } }
Globalism is Socialism on a planetary scale.
-
I shorted it down to this, and will just do a join to the master product table. Would you include the price or leave that out as well?
public class SHOPPING_CART
{
[Key()]
[Column(Order = 1)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int cart_ID { get; set; }\[Required\] public int customer\_ID { get; set; } \[Required\] \[MaxLength(80)\] public string customer\_accountName { get; set; } \[Required\] public DateTime timeStamp { get; set; } \[Required\] \[MaxLength(80)\] public string item\_Type { get; set; } \[Required\] public int item\_ID { get; set; } \[Required\] public int item\_Qty { get; set; } }
Globalism is Socialism on a planetary scale.
Since you don't seem to have quantity breaks or any other complicated calculations, and you're removing the cart once it's processed, I'd be inclined to leave the price on the product.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
I shorted it down to this, and will just do a join to the master product table. Would you include the price or leave that out as well?
public class SHOPPING_CART
{
[Key()]
[Column(Order = 1)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int cart_ID { get; set; }\[Required\] public int customer\_ID { get; set; } \[Required\] \[MaxLength(80)\] public string customer\_accountName { get; set; } \[Required\] public DateTime timeStamp { get; set; } \[Required\] \[MaxLength(80)\] public string item\_Type { get; set; } \[Required\] public int item\_ID { get; set; } \[Required\] public int item\_Qty { get; set; } }
Globalism is Socialism on a planetary scale.
Just out of the topic, but I am asking this here because I want to directly ask you, your caption says "Globalism is Socialism on a planetary scale", how, do you mean Socialism is nothing but imposing unwanted rules on mass people?, is it in that way? :)
Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."
-
Just out of the topic, but I am asking this here because I want to directly ask you, your caption says "Globalism is Socialism on a planetary scale", how, do you mean Socialism is nothing but imposing unwanted rules on mass people?, is it in that way? :)
Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."
I changed it to "21st century globalism is socialism on a planetary scale", makes more sense now. I seriously doubt anyone cares why I think this now, and I would private message you why, but I think they removed the private message feature; can't find yours. And I don't want to violate the rules of the forum by posting my thoughts on this. But I do have a well detailed anwser for it.
21st Century Globalism has become Socialism on a planetary scale, in which the unequal treaties of the past have come back into play.
-
I changed it to "21st century globalism is socialism on a planetary scale", makes more sense now. I seriously doubt anyone cares why I think this now, and I would private message you why, but I think they removed the private message feature; can't find yours. And I don't want to violate the rules of the forum by posting my thoughts on this. But I do have a well detailed anwser for it.
21st Century Globalism has become Socialism on a planetary scale, in which the unequal treaties of the past have come back into play.
It doesn't matter for me my friend, its just your opinion as I will have mine, I respect your opinion but just asked what was your logic in it. We have both things in our genes that's to protect our territory and to cross territory, it came from animal genes that they were our fathers millions of millions of years back as per Darwin sir :)
Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."
-
It doesn't matter for me my friend, its just your opinion as I will have mine, I respect your opinion but just asked what was your logic in it. We have both things in our genes that's to protect our territory and to cross territory, it came from animal genes that they were our fathers millions of millions of years back as per Darwin sir :)
Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."