Ich versuche, Dezimalwert mithilfe von LINQ in einem MVC3-Projekt zu erhalten.Wählen Sie den Dezimalwert über LINQ
Wie bekomme ich es? Es sieht einfach aus, aber ich kann nicht einen einzigen Dezimalwert nicht Liste, die Product.aWeekPrice ist.
Wie kann ich den bestimmten threeDayPrice bekommen? Nachdem sie threeDayPrice, wird es für die Gewährung unterschiedliche Bedingungen in, wenn die Bedingung verwendet werden, wie Sie unten in meinem Code zu sehen:
public decimal GetTotal(decimal price)
{
// Multiply product price by count of that album to get
// the current price for each of those product in the cart
// sum all product price totals to get the cart total
//In select part, I have got error, 'cannot convert type
//'System.Linq.IQueryable<decimal>' to 'decimal'
decimal threeDayPrice = (from cartItems in db.Cart
where cartItems.cartId == ShoppingCartId
select (decimal)cartItems.Product.threeDayPrice);
decimal aWeekPrice = (from cartItems in db.Cart
where cartItems.cartId == ShoppingCartId
select (decimal)cartItems.Product.aWeekPrice);
if (price == threeDayPrice)
{
decimal? total = (from cartItems in db.Cart
where cartItems.cartId == ShoppingCartId
select (int?)cartItems.count * cartItems.Product.threeDayPrice).Sum();
return total ?? decimal.Zero;
}
else if (price == aWeekPrice)
{
decimal? total = (from cartItems in db.Cart
where cartItems.cartId == ShoppingCartId
select (int?)cartItems.count * cartItems.Product.aWeekPrice).Sum();
return total ?? decimal.Zero;
}
}
Was ist der Datentyp von threeDayPrice/aWeekPrice? Sind sie eine Sammlung von Dezimalzahlen oder nur Dezimalzahlen? – McGarnagle
Diese Frage hat nichts mit MVC zu tun. Es ist eine Datenbank-Frage, also ist es entweder Entity Framework oder Linq zu SQL, nicht sicher, welche –