title: LINQ query to get price of product that is added in sales table
body: <p>I am New to MVC ASP.NET C#, so i am having trouble in getting product' price from ProductsList table.
  The Sales Table has a column of Total Price where price of product from ProductList is multiplied with the quantity added in Sales Table by user and total price will be calculated for that product.
  Model Class for ProductList:</p>
  <pre><code>namespace InventorySystem.Models
  {
      using System;
      using System.Collections.Generic;
      
      public partial class ProductList
      {
          
          public ProductList()
          {
              this.Inventories = new HashSet&lt;Inventory&gt;();
              this.Sales = new HashSet&lt;Sale&gt;();
          }
      
          public int ProductId { get; set; }
          public string ProductName { get; set; }
          public int ProductPrice { get; set; }
          public string ProductCategory { get; set; }
      
          
      }
  }
  </code></pre>
  <p>Model Class for Sales:</p>
  <pre><code>namespace InventorySystem.Models
  {
      using System;
      using System.Collections.Generic;
      
      public partial class Sale
      {
          public int SalesId { get; set; }
          public int ProductId { get; set; }
          public int TotalPrice { get; set; }
          public int Prod_Quantity { get; set; }
          public System.DateTime Date { get; set; }
      
          public virtual ProductList ProductList { get; set; }
      }
  }
  </code></pre>
  <p>When i add new sales it will go to create actionresult, where new sale will be added in table:</p>
  <pre><code>public ActionResult Create([Bind(Include = &quot;SalesId,ProductId,TotalPrice,Prod_Quantity,Date&quot;)] Sale sale)
          {
              if (ModelState.IsValid)
              {
                  // here with the multiplication i want the product price from products table
                  int TotalPrice = sale.Prod_Quantity * ;
                  sale.TotalPrice = TotalPrice;
                  db.Sales.Add(sale);
                  db.SaveChanges();
                  return RedirectToAction(&quot;Index&quot;);
              }
  
              ViewBag.ProductId = new SelectList(db.ProductLists, &quot;ProductId&quot;, &quot;ProductName&quot;, sale.ProductId);
              return View(sale);
          }
  </code></pre>
  <p>SS of UI:</p>
  <p><a href="https://i.stack.imgur.com/Cc46A.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Cc46A.png" alt="enter image description here" /></a></p>
  <p>As soon as i click on create button it should get the quantity from sales table and price of product from productlist table and multiply them and display under column of TotalPrice:</p>
  <p><a href="https://i.stack.imgur.com/Fp25N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Fp25N.png" alt="enter image description here" /></a></p>
  <p>CREATE VIEW:</p>
  <pre><code>@model InventorySystem.Models.Sale
  
  @{
      ViewBag.Title = &quot;Create&quot;;
  }
  
  &lt;h2&gt;Create&lt;/h2&gt;
  
  
  @using (Html.BeginForm()) 
  {
      @Html.AntiForgeryToken()
      
      &lt;div class=&quot;form-horizontal&quot;&gt;
          &lt;h4&gt;Sale&lt;/h4&gt;
          &lt;hr /&gt;
          @Html.ValidationSummary(true, &quot;&quot;, new { @class = &quot;text-danger&quot; })
         
          &lt;div class=&quot;form-group&quot;&gt;
              @Html.LabelFor(model =&gt; model.ProductId, &quot;ProductName&quot;, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
              &lt;div class=&quot;col-md-10&quot;&gt;
                  @Html.DropDownList(&quot;ProductId&quot;, null, htmlAttributes: new { @class = &quot;form-control&quot; })
                  @Html.ValidationMessageFor(model =&gt; model.ProductId, &quot;&quot;, new { @class = &quot;text-danger&quot; })
              &lt;/div&gt;
          &lt;/div&gt;
  
  
          &lt;div class=&quot;form-group&quot;&gt;
              @Html.LabelFor(model =&gt; model.Prod_Quantity, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
              &lt;div class=&quot;col-md-10&quot;&gt;
                  @Html.EditorFor(model =&gt; model.Prod_Quantity, new { htmlAttributes = new { @class = &quot;form-control&quot; } })
                  @Html.ValidationMessageFor(model =&gt; model.Prod_Quantity, &quot;&quot;, new { @class = &quot;text-danger&quot; })
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class=&quot;form-group&quot;&gt;
              @Html.LabelFor(model =&gt; model.Date, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
              &lt;div class=&quot;col-md-10&quot;&gt;
                  @Html.EditorFor(model =&gt; model.Date, new { htmlAttributes = new { @class = &quot;form-control&quot; } })
                  @Html.ValidationMessageFor(model =&gt; model.Date, &quot;&quot;, new { @class = &quot;text-danger&quot; })
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class=&quot;form-group&quot;&gt;
              &lt;div class=&quot;col-md-offset-2 col-md-10&quot;&gt;
                  &lt;input type=&quot;submit&quot; value=&quot;Create&quot; class=&quot;btn btn-default&quot; /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  }
  
  &lt;div&gt;
      @Html.ActionLink(&quot;Back to List&quot;, &quot;Index&quot;)
  &lt;/div&gt;
  
  @section Scripts {
      @Scripts.Render(&quot;~/bundles/jqueryval&quot;)
  }
  </code></pre>