как я могу бросить в cartItem?литье iqueryable
var newItem = from i in dc.CartItems
where i.productID == item.productID
select new {productID = i.productID,
Quantity = i.Quantity + item.Quantity ,
cartID = item.cartID };
CartItem itemToUpdate = (here??)newItem;
dc.CartItems.Attach(itemToUpdate, true);
Следующее решение дает мне эту ошибку>
ОШИБКА: Нет Оператор принуждения не определен между типами '<> f__AnonymousType2`3 [System.Int32, System.Int32, System.String]' и «CartItem».
как об этом коде: это делает ошибку слишком
if (IfExist(item))
{
//if this product id in cart
// get the quantity of existing cartItem
int quantity = (from i in dc.CartItems
where i.productID == item.productID
select i).First().Quantity;
// sum quanitities of existing and just inserted item
item.Quantity += quantity;
dc.CartItems.Attach(item, true);
ошибка: Невозможно добавить сущность с ключом, который уже используется.
Извините, я был не таким ясным, как мог бы быть - я обновил свой ответ, чтобы привести пример того, что я имею в виду. – reavowed
Почему он обновляет элемент при прикреплении? и дать эту ошибку – freeTayyeb