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
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);
问题描述的不够详细,这样虽然可以满足要求,代码还是有点长。
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);
可以根据这个来写