首页 新闻 会员 周边 捐助

SQL 转成LINQ 请教

0
悬赏园豆:10 [待解决问题]

  select sqc_name,sqc_code from [ald_address_New].[dbo].[tb_address_SQC] t1 where 
  sqc_parentXzcCode is null and sqc_code not in
  (  select distinct sqc_parentXzcCode from [ald_address_New].[dbo].[tb_address_SQC] 
  where sqc_parentXzcCode is not null 
  )
  union
  select isnull(t2.sqc_name,'')+t1.sqc_name,t1.sqc_code from [ald_address_New].[dbo].[tb_address_SQC] t1 
  left join [ald_address_New].[dbo].[tb_address_SQC] t2 on t1.sqc_parentXzcCode=t2.sqc_code
  where   t1.sqc_parentXzcCode is not null 

将上面的SQL语句转成LINQ语句 ,感谢

问题补充:

问题解决,未测试性能,代码如下:

1 var q = (from p in aae.tb_address_SQC
2 where p.sqc_xzjd_code == id && p.sqc_parentXzcCode == null && !((from t in aae.tb_address_SQC
3 where
4 t.sqc_xzjd_code == id &&
5 t.sqc_parentXzcCode != null
6 select t.sqc_parentXzcCode).
7 Distinct()).Contains(
8 p.sqc_code)
9 select new {name = p.sqc_name, code = p.sqc_code, parent = p.sqc_xzjd_code}).Union(
10 from p1 in aae.tb_address_SQC
11 from p2 in aae.tb_address_SQC
12 where p1.sqc_xzjd_code == id && p1.sqc_parentXzcCode == p2.sqc_code
13 select
14 new
15 {
16 name = (p2.sqc_name == null ? "" : p2.sqc_name) + p1.sqc_name,
17 code = p1.sqc_code,
18 parent = p1.sqc_xzjd_code
19 }
20 );
忧郁的匹格的主页 忧郁的匹格 | 初学一级 | 园豆:190
提问于:2011-08-02 13:56
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册