求一linq语句

马少华 2012-05-15 10:24:05
表ta
ID Name Atext

表tb
AID CID

表tc
ID Ctext


sql语句如下:
select ta.*,count(ta.Name) as NameCount,tc.Ctext from ta join tb on ta.ID=tb.AID join tc on tc.ID=tb.CID
where tc.Ctext = strMyCondition
group by ta.Name,ta.ID,ta.Atext,tc.Ctext
这个问题折磨了我一个晚上。
...全文
81 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
马少华 2012-05-15
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

C# code
var query = from a in db.ta
join b in db.tb on ta.id equals tb.id into j1
join c in db.tc on tc.id equals j1.cid into j
where j.ctext == strMyCondition
……
[/Quote]
不知道你测试过没有,
join c in db.tc on tc.id equals j1.cid into j
j1里面没有ta的字段
threenewbee 2012-05-15
  • 打赏
  • 举报
回复
var query = from a in db.ta
join b in db.tb on ta.id equals tb.id into j1
join c in db.tc on tc.id equals j1.cid into j
where j.ctext == strMyCondition
group j by new { j.name, j.id, j.atext, j.ctext } into g
select new { g.First(), NameCount = g.Count() };
threenewbee 2012-05-15
  • 打赏
  • 举报
回复
var query = from a in db.ta
join b in db.tb on ta.id equals tb.id into j1
join c in db.tc on tc.id equals j1.cid into j
where j.ctext == strMyCondition
group j by new { j.name, j.id, j.atext, j.ctext } into g
select new { g, NameCount = g.Count() };
马少华 2012-05-15
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

C# code
var query = from a in db.ta
join b in db.tb on ta.id equals tb.id into j
where j.ctext == strMyCondition
group j by new { j.name, j.id, j.atext, j.ctext }……
[/Quote]
哥们儿,我这是三表连接
threenewbee 2012-05-15
  • 打赏
  • 举报
回复
var query = from a in db.ta
join b in db.tb on ta.id equals tb.id into j
where j.ctext == strMyCondition
group j by new { j.name, j.id, j.atext, j.ctext } into g
select new { g, NameCount = g.Count() };
马少华 2012-05-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

http://www.cnblogs.com/ASPNET2008/archive/2008/12/21/1358152.html
[/Quote]
看过了,还不是很明白

17,741

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧