我使用的是Asp.Net Entity Framework。我有2个表,我想在不同表中的两个变量之间做一个减号。我加入了但是没有用。这是我的代码:
var prod_items = (from prod in entity.ProductSet
join ca in entity.CartSet
on prod.ProductID equals ca.Product_ProductID
where ca.Customer_CustomerID.Equals(id)
select new { ca.Quantity,prod.ProductStock,prod.ProductID });
int h;
foreach (var nbr in prod_items)
{
h = nbr.ProductStock - nbr.Quantity;
ProductSet p = entity.ProductSet
.Where(i => i.ProductID == nbr.ProductID)
.FirstOrDefault();
p.ProductStock = h;
}
我收到的错误如ArgumentException
未被用户代码处理。
答案 0 :(得分:0)
您可以尝试这样的事情:
var prod_items = (from prod in entity.ProductSet
join ca in entity.CartSet
on prod.ProductID equals ca.Product_ProductID
where ca.Customer_CustomerID.Equals(id)
select new ProductSet
{
ProductID = prod.ProductID,
ProductStock = prod.ProductStock - ca.Quantity,
// Set the values for th rest properties.
});