【发布时间】:2008-12-09 03:42:10
【问题描述】:
我需要对数据库表中的时间段 (Period) 和表中的发票列表 (Invoice) 执行 LINQ 查询,这些发票位于该期间的开始日期和结束日期内。两个表之间没有key引用,如何进行Invoice子查询?
我正在尝试做类似以下的事情:
var query = (from p in db.DataContext.Periods
// Subquery i in db.DataContext.Invoices
let InvoiceAmount = i.Where(t => t.InvoiceDate >= p.StartDate && t.InvoiceDate <= p.EndDate)
select new PeriodView
(
p.Name,
p.StartDate,
p.EndDate,
InvoiceAmount.Count()
));
【问题讨论】: