在线等!!!急急急!!!翻译LINQ语句

zyglovewhj 2010-09-26 03:03:32
select '收入' as kemu,isnull(sum(money),0)as money
from [statistics]
where SortType =1 and SortId in (
select Id from CashflowSort where CorpMoneySign =1)

union all

select '--'+c.Title,c.Allmoney from (
select Title,isnull(SUM(money),0) Allmoney,CorpMoneySign ,a.Id
from CashflowSort a
left join [statistics]
on
SortType=1 and a.Id= SortId
group by Title,CorpMoneySign,a.Id) c
where c.corpMoneySign =1 and c.Id not in
(select distinct ParentId from CashflowSort )

翻译成LINQ
...全文
134 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
huminghua 2010-09-27
  • 打赏
  • 举报
回复

最后你要的结果:
var listID=from c in CashflowSort
where c.CorpMoneySign ==1
select c.Id;
var lList=from a in CashflowSort join s in statistics
on s.SortType==1 && a.SortId==s.SortId into ss
group ss by new
{
ss.Title,
ss.CorpMoneySign,
ss.Id
} into ssa
select new
{
Title=ssa.Title,
Allmoney=ssa.Sum(ssa=>ssa.money)==null?0:ssa.Sum(ssa=>ssa.money),
CorpMoneySign=ssa.CorpMoneySign,
ssa.Id
};

var dl=(from cf in CashflowSort select cf.ParentId).Distinct();

(from s in statistics
group s by s.money into t
where s.SortType ==1
&& listID.Contains(s.SortId)
select new
{
kemu='收入',
money=t.Sum(t=>t.money)==null?0:t.Sum(t=>t.money)
}).Contact(from c in lList where c.corpMoneySign==1 && !(dl).Contains(c.Id) select new{'--'=c.Title,c.Allmoney})

huminghua 2010-09-27
  • 打赏
  • 举报
回复
select '--'+c.Title,c.Allmoney from (
select Title,isnull(SUM(money),0) Allmoney,CorpMoneySign ,a.Id
from CashflowSort a
left join [statistics]
on
SortType=1 and a.Id= SortId
group by Title,CorpMoneySign,a.Id) c
where c.corpMoneySign =1 and c.Id not in
(select distinct ParentId from CashflowSort )

翻译成LINQ
var lList=from a in CashflowSort join s in statistics
on s.SortType==1 && a.SortId==s.SortId into ss
group ss by new
{
ss.Title,
ss.CorpMoneySign,
ss.Id
} into ssa
select new {'--'=ssa.Title,ssa.Allmoney};

var dl=(from cf in CashflowSort select cf.ParentId).Distinct();

var nextQuery=from c in lList where c.corpMoneySign==1 && !(dl).Contains(c.Id)
huminghua 2010-09-27
  • 打赏
  • 举报
回复
恩!楼上多说对啦!我没仔细写。。幸好你指出来!谢谢!我也是才刚学Linq想来这里学习一下!嘿嘿!楼上好仔细哦!呵呵!
q107770540 2010-09-27
  • 打赏
  • 举报
回复


select '收入' as kemu,isnull(sum(money),0)as money
from [statistics]
where SortType =1 and SortId in (
select Id from CashflowSort where CorpMoneySign =1)

//针对上边的SQL 语句,我写了下边的LINQ
var listID=from c in CashflowSort
where c.CorpMoneySign ==1
select c.Id;

var query= from s in statistics
group s by s.money into t
where s.SortType ==1
&& listID.Contains(s.SortId)
select new
{
kemu='收入',
money=t.Sum(t=>t.money)==null?0:t.Sum(t=>t.money)
}

q107770540 2010-09-27
  • 打赏
  • 举报
回复
and 在linq中应该是 && 吧。。
q107770540 2010-09-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 huminghua 的回复:]

(from s in statistics where s.SortType=1 and (from c in CashflowSort where c.CorpMoneySign==1 select c.Id).Contains(s.SortType) select new{'收入' as s.kemu,isnull(statistics.Sum(a=> a.money),0) as s.mo……
[/Quote]
据我所知
1.linq语句中where后应该是== 吧: where s.SortType==1
select new 中应该这样写吧:


select new
{
收入 = s.kemu,
money= statistics.Sum(a=> a.money)==null?O:statistics.Sum(a=> a.money))
}
哥子谭 2010-09-27
  • 打赏
  • 举报
回复
问题怎么这么复杂哦
huminghua 2010-09-27
  • 打赏
  • 举报
回复
谢谢楼上的啊!你不来回复我就回复不了啦!
huminghua 2010-09-27
  • 打赏
  • 举报
回复
(from s in statistics
group s by s.money into t
where s.SortType ==1
&& listID.Contains(s.SortId)
select new
{
kemu='收入',
money=t.Sum(t=>t.money)==null?0:t.Sum(t=>t.money)
}).Concat
(from c in lList where c.corpMoneySign==1 && !(dl).Contains(c.Id)
select new
{
c.Title='--',
c.Allmoney
}
)
不知道是否正确!你自己试试!请高手指点一二! //一个用户只允许连续回复3次。连续是指的多久啊!
mingming912 2010-09-27
  • 打赏
  • 举报
回复
好复杂
bancxc 2010-09-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 huminghua 的回复:]
(from s in statistics where s.SortType=1 and (from c in CashflowSort where c.CorpMoneySign==1 select c.Id).Contains(s.SortType) select new{'收入' as s.kemu,isnull(statistics.Sum(a=> a.money),0) as s.mon……
[/Quote]nb.
huminghua 2010-09-26
  • 打赏
  • 举报
回复
(from s in statistics where s.SortType=1 and (from c in CashflowSort where c.CorpMoneySign==1 select c.Id).Contains(s.SortType) select new{'收入' as s.kemu,isnull(statistics.Sum(a=> a.money),0) as s.money}).Contact
(后面的自己写) 貌似没有ISNUll这个,你换成=吧!呵呵~!

8,497

社区成员

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

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