請將以下SQL轉換成Linq to sql?

yyy342921318 2010-10-28 09:02:08
sql語句如下,請幫忙轉成linq to sql ,求解~


SELECT     *
FROM COPTC INNER JOIN
COPTD ON COPTC.TC001 = COPTD.TD001 AND COPTC.TC002 = COPTD.TD002 RIGHT OUTER JOIN
MOCTA ON COPTD.TD001 = MOCTA.TA026 AND COPTD.TD002 = MOCTA.TA027 AND
COPTD.TD003 = MOCTA.TA028
WHERE (MOCTA.TA013 IN ('Y', 'y')) AND (COPTC.TC027 IN ('Y', 'y')) AND (CONVERT(DATETIME, MOCTA.TA003) BETWEEN CONVERT(DATETIME,
'2010-07-20 00:00:00', 102) AND CONVERT(DATETIME, '2010-12-31 00:00:00', 102))
...全文
85 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
兔子党-督察 2010-10-28

var query= from cc in COPTC
join cd in COPTD
on new {cc.TC001,cc.TC002} equals new{ cd.TD001,cd.TD002}
into m
from n in m.DefaultIfEmpty()
join ma in MOCTA
on new{cd.TD001, cd.TD002,cd.TD003 } equals new{ ma.TA026,ma.TA027,ma.TA028}

where new char[]{'Y','y'}.Contains(ma.TA013)
&& new char[]{'Y','y'}.Contains(cc.TC027)
&& Convert.ToDateTime(ma.TA003) > Convert.ToDateTime("2010-07-20")
&& Convert.ToDateTime(ma.TA003) < Convert.ToDateTime("2010-12-31")
select new
{
cc,
cd
};
回复
yyy342921318 2010-10-28
[Quote=引用 3 楼 q107770540 的回复:]
C# code


var query= from cc in COPTC
join cd in COPTD
on cc.TC001 equals cd.TD001
&& cc.TC002 equals cd.TD002
into m
from n in ……
[/Quote]
谢谢你的回答啊,这里提示有问题呢?在这一句

&& cc.TC002 equals cd.TD002

join on的用法怎样带多个呀?谢谢了啊
回复
兔子党-督察 2010-10-28


var query= from cc in COPTC
join cd in COPTD
on cc.TC001 equals cd.TD001
&& cc.TC002 equals cd.TD002
into m
from n in m.DefaultIfEmpty()
join ma in MOCTA
on cd.TD001 equals ma.TA026
&& cd.TD002 equals ma.TA027
&& cd.TD003 equals ma.TA028
where new char[]{'Y','y'}.Contains(ma.TA013)
&& new char[]{'Y','y'}.Contains(cc.TC027)
&& Convert.ToDateTime(ma.TA003) > Convert.ToDateTime("2010-07-20")
&& Convert.ToDateTime(ma.TA003) < Convert.ToDateTime("2010-12-31")
select new
{
cc,
cd
};


回复
兔子党-督察 2010-10-28
代码手写,未测试
仅供参考
回复
兔子党-督察 2010-10-28



var query= from cc in COPTC
join cd in COPTD
on cc.TC001 equals cd.TD001
&& cc.TC002 equals cd.TD002
into m
from n in m
join ma in MOCTA
on cd.TD001 equals ma.TA026
&& cd.TD002 equals ma.TA027
&& cd.TD003 equals ma.TA028
where new char[]{'Y','y'}.Contains(ma.TA013)
&& new char[]{'Y','y'}.Contains(cc.TC027)
&& Convert.ToDateTime(ma.TA003) > Convert.ToDateTime("2010-07-20")
&& Convert.ToDateTime(ma.TA003) < Convert.ToDateTime("2010-12-31")
select new
{
cc,
cd
}
回复
yyy342921318 2010-10-28
[Quote=引用 5 楼 q107770540 的回复:]
C# code

var query= from cc in COPTC
join cd in COPTD
on new {cc.TC001,cc.TC002} equals new{ cd.TD001,cd.TD002}
into m
from n in m.DefaultIfEmpty()
……
[/Quote]

这这正是我需要的,非常感谢了~~~
回复
相关推荐
发帖
非技术区
创建于2007-09-28

7707

社区成员

.NET技术 非技术区
申请成为版主
帖子事件
创建了帖子
2010-10-28 09:02
社区公告
暂无公告