【发布时间】:2019-07-31 11:28:55
【问题描述】:
我有三张桌子:
service_group
{
id,
title
}
service
{
id,
title,
group_id
}
service_rate
{
id,
title,
service_id,
price,
date
}
我有一个group_service 的组合框,用户必须选择一个然后打开一个表单,用户可以从service_rate 列表中进行选择。
service_rate 列表包括所有servic_rate 和service_id 在service.id 和selected service_group_id。
如果我的英语说得不好,请见谅。
我的代码:
var list = (
from p in db.Tbl_Services
where p.Service_Group_ID == _service_group_id
select new {
p.ID,
p.Title,
p.Tbl_Services_Rate.Where(m = > m.Service_ID == p.ID).Last().Price,
p.Tbl_Services_Rate.Where(m = > m.Service_ID == p.ID).Last().date
}).ToList();
但似乎不起作用。
【问题讨论】:
-
问题是什么?
-
我的代码不起作用。我想要一个这样的 linq 查询
-
你想要一个 linq 查询来做什么?
-
我想要一个与此 sql 查询等效的 linq 查询:select * from Tbl_Services_Rate where Service_ID in (select ID from Tbl_Services where Service_Group_ID = 2)
-
您想要所选服务组下的所有服务的 service_rate 吗?
标签: c# entity-framework linq lambda linq-to-sql