首页 新闻 搜索 专区 学院

这句SQL怎么改成LINQ

0
悬赏园豆:10 [已解决问题] 解决于 2014-07-09 08:56

SELECT MATCHDEPINFO.*,dep.DEP_ALL_CODE FROM MATCHDEPINFO LEFT JOIN dep ON dep.DEP_CODE=MATCHDEPINFO.DEPCODE WHERE MAINDEPCODE=(SELECT DEP_CODE FROM DEP WHERE DEP_CLASS=3 AND DEP_CODE='{0}' AND ROWNUM<2) ORDER BY CAST(MATCHDEPINFO.NEIGHBORING_DISTANCE AS FLOAT), dep.LDAP", dep_code

许大虾的主页 许大虾 | 初学一级 | 园豆:12
提问于:2014-06-11 16:29
< >
分享
最佳答案
0

var dataContext = new DataClassesDataContext();

var dep_code = "1101";
var query = (from m in dataContext.MATCHDEPINFO join d in dataContext.dep on m.DEPCODE equals            

        d.DEP_CODE into t from dm in t.DefaultIfEmpty() where  m.MAINDEPCODE ==

        dataContext.dep.Where(z => z.DEP_CLASS == 3 && z.DEP_CODE == dep_code && z.ROWNUM < 2)
             .Select(z => new {z.DEP_CODE}).FirstOrDefault().DEP_CODE
        select new {
                        m.DEPCODE,
                        m.MAINDEPCODE,
                        m.NEIGHBORING_DISTANCE,
                        dm.DEP_ALL_CODE,
                        dm.DEP_CLASS,
                        dm.DEP_CODE,
                        dm.LDAP,
                        dm.ROWNUM
                    }).OrderBy(z => z.NEIGHBORING_DISTANCE).ThenBy(z => z.LDAP);

 

    问题描述的不够详细,这样虽然可以满足要求,代码还是有点长。

收获园豆:10
Jinwen | 初学一级 |园豆:176 | 2014-06-12 10:09
其他回答(1)
0

var roe = DB.h3_Role.Where(r => r.rId == 8).Select(p => p.rId).AsQueryable();
   var roleId = 0;
   if (roe != null) {
    roleId = roe.First();
   }
   var poco = DB.h3_Organiza.Join(DB.h3_User, o => o.oId, u => u.oId, (o, u) => new { o, u }).Select(a => new { a.o, a.u.uName, a.u.roleId }).Where(a => a.roleId == roleId);

可以根据这个来写

ゞ蓦然灬淺笑ゞ | 园豆:228 (菜鸟二级) | 2014-06-17 11:11
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册