【发布时间】:2010-12-15 11:55:31
【问题描述】:
使用 linq 连接到数据库的实体,该数据库中有表,其中包含与工作具有多对多关系的付款。这是通过分配表实现的。我想要一个包含所有工作的列表框,其中包含一个名为到期价格的列,该列包含该工作的所有付款分配并将其从工作价格中扣除。但是,使用下面的 linq to entity 语句。问题是,如果作业没有分配,则返回 null,因此到期付款为空。我真正想要的是,如果没有分配,到期付款就是工作价格,但是,我想不出办法解决这个问题。请在我最终发疯之前提供帮助:-(
var jobs = from j in data.jobs
where j.property.customer.id == customerid
&& j.completed != null
select new
{
j.id,
j.price,
dueprice = j.price - ( from a in data.allocs
where a.job.id == j.id
select a.amount ).Sum(),
lineone = j.property.lineone,
postcode = j.property.postcode,
jobtype = j.jobtype.name,
j.completed
};
【问题讨论】:
标签: c# .net asp.net linq linq-to-entities