Silverlight 左连接,自定义实体问题
这里多出一个字段,怎样自定义一个实体。代码我是这样写的,另外新建了一个实体类,但是在页面访问不到这个方法
public IQueryable<RoleAndMyRoleModel> GetRoleAndMyRole(string userId)
{
return (from r in ObjectContext.T_Role
from I in
(from r2 in ObjectContext.T_Role
join ur in ObjectContext.T_User_Role on r2.ROLE_CODE equals ur.ROLE_CODE
join u in ObjectContext.T_UserBase on ur.UserID equals u.UserID
select new { IRoleCode = r2.ROLE_CODE })
select new RoleAndMyRoleModel
{
Role_Code = r.ROLE_CODE,
Role_Name = r.ROLE_NAME,
Role_Desc = r.ROLE_DESC,
IRoleCode = I.IRoleCode
}).AsQueryable<RoleAndMyRoleModel>();
}
想要实现的SQL语句是这样的,我该怎样改呢。求各位大神指导!
SELECT *
FROM T_Role [Role]
LEFT JOIN
(
SELECT R.ROLE_CODE AS IRoleCode FROM T_Role AS R
JOIN T_User_Role AS UR ON R.ROLE_CODE=UR.ROLE_CODE
JOIN T_UserBase AS U ON UR.UserID=U.UserID AND U.UserID=@UserID
) I ON [Role].ROLE_CODE=I.IRoleCode
[解决办法]
手写,仅供参考:
var result=from u in IRoleCode
join n in T_User_Role on u.ROLE_CODE equals n.ROLE_CODE
join m in T_UserBase on new n.UserID equals m.UserID into g
from p in g.DefaultIfEmpty()
join q in T_Role on p.IRoleCode equals q.ROLE_CODE into s
from x in s.DefaultIfEmpty()
where x.UserID=UserID
select new RoleAndMyRoleModel
{
Role_Code = x.ROLE_CODE,
Role_Name = x.ROLE_NAME,
Role_Desc = x.ROLE_DESC,
IRoleCode = x.IRoleCode
};