Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Join or the nomemclature for join using EF in c#

Join or the nomemclature for join using EF in c#

Scheduled Pinned Locked Moved Database
csharpdatabasedesignsales
12 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jkirkerx
    wrote on last edited by
    #1

    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.

    Richard DeemingR 1 Reply Last reply
    0
    • J jkirkerx

      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.

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      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

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      J 2 Replies Last reply
      0
      • Richard DeemingR Richard Deeming

        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

        J Offline
        J Offline
        jkirkerx
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          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

          J Offline
          J Offline
          jkirkerx
          wrote on last edited by
          #4

          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.

          Richard DeemingR 1 Reply Last reply
          0
          • J jkirkerx

            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.

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            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

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            J 2 Replies Last reply
            0
            • Richard DeemingR Richard Deeming

              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

              J Offline
              J Offline
              jkirkerx
              wrote on last edited by
              #6

              I went too far on duplicating fields in the shopping cart. Now that I have the Automatic Migration working, I think I'll trim that down.

              Globalism is Socialism on a planetary scale.

              1 Reply Last reply
              0
              • Richard DeemingR Richard Deeming

                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

                J Offline
                J Offline
                jkirkerx
                wrote on last edited by
                #7

                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.

                Richard DeemingR I 2 Replies Last reply
                0
                • J jkirkerx

                  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.

                  Richard DeemingR Offline
                  Richard DeemingR Offline
                  Richard Deeming
                  wrote on last edited by
                  #8

                  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

                  "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                  1 Reply Last reply
                  0
                  • J jkirkerx

                    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 Offline
                    I Offline
                    indian143
                    wrote on last edited by
                    #9

                    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."

                    J 1 Reply Last reply
                    0
                    • I indian143

                      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."

                      J Offline
                      J Offline
                      jkirkerx
                      wrote on last edited by
                      #10

                      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 1 Reply Last reply
                      0
                      • J jkirkerx

                        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 Offline
                        I Offline
                        indian143
                        wrote on last edited by
                        #11

                        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."

                        J 1 Reply Last reply
                        0
                        • I indian143

                          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."

                          J Offline
                          J Offline
                          jkirkerx
                          wrote on last edited by
                          #12

                          Sign Up | LinkedIn[^] My contact info is here, just drop me an email and then I will delete this post

                          21st Century Globalism has become Socialism on a planetary scale, in which the unequal treaties of the past have come back into play.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups