4
Is there any faster (performative) way to compare the current value with the previous (bank) value with Entity Framework? Instead of selecting Id for Id (according to property Discount code below), check the array or something like?
With the code below, I check the last price of the value and calculate the discount, however, is made Id for Id.
ha.AddRange(
array.Select(
x => new ProductHistory {
ProductId = x.Id
, Price = x.Price
, LastUpdate = DateTime.Now.Date
, Discount = x.Price / (
(Convert.ToDecimal(db.ProductHistory.Where((ProductHistory p) => x.Id == p.ProductId)
.OrderByDescending(o => o.LastUpdate)
.Select(y => y.Price)
.FirstOrDefault()) == 0) ? x.Price :
(Convert.ToDecimal(db.ProductHistory.Where((ProductHistory p) => x.Id == p.ProductId)
.OrderByDescending(o => o.Id)
.Select(y => y.Price)
.FirstOrDefault()))) * 100 - 100
}
)
);
Just so I understand: what it is
haand what isarray?– Leonel Sanches da Silva
ha = Producthistory[] array = Product[]
– Ploshvisk
I put as array because the Entity Addorupdate only accepts array, if it would not be a list.
– Ploshvisk