SELECT
/*MATERIAL COST USD*/
Material_Cost_Gbp * Material_Rate_Usd AS Material Cost Usd,
/*MATERIAL COST BURDEN & SCRAP*/
((Material_Cost_Gbp * Material_Rate_Usd) * Material_Rate_Burden / 100)
+ ((Material_Cost_Gbp * Material_Rate_Usd) * Material_Rate_Scrap / 100)
+ (Material_Cost_Gbp * Material_Rate_Usd) AS Material Cost Burden & Scrap,
/*MATERIAL COST PER PCS*/
(((Material_Cost_Gbp * Material_Rate_Usd) * Material_Rate_Burden / 100)
+ ((Material_Cost_Gbp * Material_Rate_Usd) * Material_Rate_Scrap / 100)
+ (Material_Cost_Gbp * Material_Rate_Usd)) / Qty_Bar AS Material Cost per Pcs
FROM
dbo.Nmaterial
How can I insert this query code for display in web page using ASP.NET MVC 5?
I assume you have installed EF in your project. First you need to create a View Model. For example:
public class TestVM
{
public string EX1 { get; set; }
public decimal EX2 { get; set; }
public decimal EX3 { get; set; }
}
After that you can map your query to the view model property
IncendoContext db = new IncendoContext(); // This is your own db context
string _sqlcom = "Select a as EX1, b as EX2, c as EX3 from Table";
List<TestVM> result = db.Database.SqlQuery<TestVM>(_sqlcom).ToList();
return View(result);
Note that the property name has to be similar to your query as xxxxx
You need to change your query, you cannot have any space (after as) to define your query property name anyway.
Under the View, just may just simply list the property
@model IEnumerable<Incendo.Web.ViewModel.TestVM>
@{
ViewBag.Title = "Test123";
}
<table>
@foreach (var item in Model)
{
<tr>
<td> @item.EX1</td>
<td>@item.EX2</td>
<td>@item.EX3</td>
</tr>
}
</table>
Please define your own namespace property. Leave a message if you have any problem.