LINQ to SQL 连接和 If 条件
我有下面的查询,如果 bstock 不为 null 并且 bstock.Price (bstock.Price 为 null-),我想在其中设置价格能加倍吗?)不为空。该连接是左外连接。有人可以帮助我吗?
var bstocks = (from p in qry
join bstock in bstockRepository.Select() on p.StockCode equals bstock.StockCode
into J1
from bstock in J1.DefaultIfEmpty()
select new
{
p.StockCode,
p.Description,
p.ListPrice,
p.Price = bstock.Price != null ? bstock.Price : p.Price,
p.QuantityOnHand ,
p.Cube,
p.ShippingFormat,
p.Weight,
p.NextShipment,
p.NextShipment2,
p.NextShipmentQuantity,
p.NextShipment2Quantity,
Bstock = p.Bstock
}
).AsQueryable();
I have the query below where I want to set the price if bstock is not null and bstock.Price (bstock.Price is a null-able doubel? ) is not null. The join is a left outer join. Can someone help me?
var bstocks = (from p in qry
join bstock in bstockRepository.Select() on p.StockCode equals bstock.StockCode
into J1
from bstock in J1.DefaultIfEmpty()
select new
{
p.StockCode,
p.Description,
p.ListPrice,
p.Price = bstock.Price != null ? bstock.Price : p.Price,
p.QuantityOnHand ,
p.Cube,
p.ShippingFormat,
p.Weight,
p.NextShipment,
p.NextShipment2,
p.NextShipmentQuantity,
p.NextShipment2Quantity,
Bstock = p.Bstock
}
).AsQueryable();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您运行左连接时,
bstock
在您的查询中可以为 null。所以你需要考虑到:结果:
bstock
can be null in your query, as you are running left join. So you need to account for that:Result: