Patrick Rice-O'Connor
asked on
Razor page - Two instances of the same table give same results
I have a data model like so:
Now the problem is that @Html.DisplayFor(model => model.IFSmain.FreeStock) and @Html.DisplayFor(model => model.IFSWA.FreeStock) give the same value. I've checked in sql and they are different, in a trace it runs two different queries, but in the debugger the FReeStock properties are the same.
using System;
using System.ComponentModel.DataAnnotations.Schema;
namespace CB_RepWebApp.Models.DataModel
{
[Table("FreeStockView")]
public class FreeStockView
{
[Column("ItemCode")]
public string ID { get; set; }
public string WarehouseCode { get; set; }
public string UM { get; set; }
public Decimal FreeStock { get; set; }
}
}
And my Item.cshtml.cs page is like this:using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using CB_RepWebApp.Models;
namespace CB_RepWebApp.Pages.Inventory
{
public class ItemModel : PageModel
{
private readonly CB_RepWebApp.Data.CRMContext _context;
public ItemModel(CB_RepWebApp.Data.CRMContext context)
{
_context = context;
_contextB = context;
}
public Models.DataModel.InventoryItem Item { get; set; }
public Models.DataModel.InventoryItem I { get; set; }
public Models.DataModel.InventoryItemPricingDetail ItemPricing { get; set; }
public Models.DataModel.ItemCostPricesView_C ItemCosting { get; set; }
public Models.DataModel.InventoryUnitMeasureBoxView_C IB { get; set; }
public Models.DataModel.FreeStockView IFSWA { get; set; }
public Models.DataModel.FreeStockView IFSmain { get; set; }
public int IFS_Total { get; set; }
public async Task<IActionResult> OnGetAsync(string id)
{
if (id == null)
{
return NotFound();
}
Models.DataModel.InventoryItem Item = await _context.InventoryItem.FirstOrDefaultAsync(m => m.ItemName == id);
I = await _context.InventoryItem.FirstOrDefaultAsync(m => m.ItemName == id);
ItemPricing = await _context.InventoryItemPricingDetail.FirstOrDefaultAsync(m => m.ItemCode == Item.ID && m.CurrencyCode == "AUD");
ItemCosting = await _context.ItemCostPricesView_C.FirstOrDefaultAsync(m => m.ItemCode == Item.ID);
IB = await _context.InventoryUnitMeasureBoxView_C.FirstOrDefaultAsync(m => m.ID == Item.ID);
IFSmain = await _context.FreeStockView.SingleOrDefaultAsync(q => q.WarehouseCode.Equals("MAIN") && q.UM.Equals("EACH") && q.ID.Equals(I.ID));
IFSWA = await _context.FreeStockView.SingleOrDefaultAsync(q => q.WarehouseCode.Equals("WA3PL") && q.UM.Equals("EACH") && q.ID.Equals(I.ID));
IFS_Total = (int)ItemVModel.IFSmain.FreeStock + (int)IFSWA.FreeStock;
return Page();
}
}
}
And my Item.cshtml page is:@page
@model CB_RepWebApp.Pages.Inventory.ItemModel
@{
ViewData["Title"] = "Item";
}
<h2> @Html.DisplayFor(model => model.I.ItemName)</h2>
<hr />
<dl class="dl-horizontal">
<dt>
Description
</dt>
<dd>
@Html.DisplayFor(model => model.I.ItemDescription_C)
</dd>
<dt>
MinQty
</dt>
<dd>
@Html.DisplayFor(model => model.I.MinQty_C)
</dd>
<dt>
MaxQty
</dt>
<dd>
@Html.DisplayFor(model => model.I.MaxQty_C)
</dd>
<dt>
Barcode
</dt>
<dd>
@Html.DisplayFor(model => model.I.BarCode_C)
</dd>
<dt>
Base selling price
</dt>
<dd>
$@Html.DisplayFor(model => model.ItemPricing.WholesalePrice)
</dd>
<dt>
Level A
</dt>
<dd>
$@Html.DisplayFor(model => model.ItemPricing.WholesalePrice2_C)
</dd>
<dt>
Level B
</dt>
<dd>
$@Html.DisplayFor(model => model.ItemPricing.WholesalePrice3_C)
</dd>
<dt>
Level C
</dt>
<dd>
$@Html.DisplayFor(model => model.ItemPricing.WholesalePrice4_C)
</dd>
<dt>
Level D
</dt>
<dd>
$@Html.DisplayFor(model => model.ItemPricing.WholesalePrice5_C)
</dd>
<dt>
Level E
</dt>
<dd>
$@Html.DisplayFor(model => model.ItemPricing.WholesalePrice6_C)
</dd>
<dt>
Level F
</dt>
<dd>
$@Html.DisplayFor(model => model.ItemPricing.WholesalePrice10_C)
</dd>
<dt>
Supplier Cost
</dt>
<dd>
$@Html.DisplayFor(model => model.ItemCosting.Cost)
</dd>
<dt>
Last Cost
</dt>
<dd>
$@Html.DisplayFor(model => model.ItemCosting.LastCost)
</dd>
<dt>
Average Cost
</dt>
<dd>
$@Html.DisplayFor(model => model.ItemCosting.AverageCost)
</dd>
<dt>
Standard Cost
</dt>
<dd>
$@Html.DisplayFor(model => model.ItemCosting.StandardCost)
</dd>
<dt>
Backorder ETA
</dt>
<dd>
@Html.DisplayFor(model => model.I.BOETA_C)
</dd>
<dt>
Box Quantity
</dt>
<dd>
@Html.DisplayFor(model => model.IB.UnitMeasureQty)
</dd>
<dt>
MPX Stock
</dt>
<dd>
@Html.DisplayFor(model => model.I.MPXStock_C)
</dd>
<dt>
Stock Levels
</dt>
<dd>
<table>
<thead>
<tr>
<th>
Location
</th>
<th>
Physical
</th>
<th>
Committed
</th>
<th>
Incoming
</th>
<th>
Free
</th>
</tr>
</thead>
<tbody>
<tr>
<td>Primary Location</td>
<td></td>
<td></td>
<td></td>
<td>@Html.DisplayFor(model => model.IFSmain.FreeStock)</td>
</tr>
<tr>
<td>Sheffield WA 3PL</td>
<td></td>
<td></td>
<td></td>
<td>@Html.DisplayFor(model => model.IFSWA.FreeStock)</td>
</tr>
<tr>
<td>Totals</td>
<td></td>
<td></td>
<td></td>
<td>@Html.DisplayFor(model => model.IFS_Total)</td>
</tr>
</tbody>
</table>
</dd>
</dl>
Now the problem is that @Html.DisplayFor(model => model.IFSmain.FreeStock) and @Html.DisplayFor(model => model.IFSWA.FreeStock) give the same value. I've checked in sql and they are different, in a trace it runs two different queries, but in the debugger the FReeStock properties are the same.
Thanks phoffric.
@Patrick,
Could you put a debugger after these two lines in your controller and check what values you are getting.
Regards,
Chinmay.
@Patrick,
Could you put a debugger after these two lines in your controller and check what values you are getting.
IFSmain = await _context.FreeStockView.SingleOrDefaultAsync(q => q.WarehouseCode.Equals("MAIN") && q.UM.Equals("EACH") && q.ID.Equals(I.ID));
IFSWA = await _context.FreeStockView.SingleOrDefaultAsync(q => q.WarehouseCode.Equals("WA3PL") && q.UM.Equals("EACH") && q.ID.Equals(I.ID));
Regards,
Chinmay.
You have said the results are the same - not if it is correct for one of the tables. There is a difference.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Welcome to EE. I am more than happy to help you here but your current code is bit unreadable.
Can you please add [ code ] [ /code ] tags to mark your model, view and controller.
Regards,
Chinmay.