用linq to sql 把这个sql语句写出来,感激不尽
sql语句:selecta.roleid,a.role,(selectcount(0)fromuserinfowhereroleid=a.roleid)asProNumf...
sql语句:select a.roleid,a.role,(select count(0) from userinfo where roleid=a.roleid) as ProNum from role a order by a.roleid desc
展开
2个回答
展开全部
from r in {yourDataContext}.role
orderby r.roleid descending
select new { r.roleid,r.role,ProNum = (from u in {yourDataContext}.userinfo select u where u.roleid == r.roleid).Count() };
大概是吧
orderby r.roleid descending
select new { r.roleid,r.role,ProNum = (from u in {yourDataContext}.userinfo select u where u.roleid == r.roleid).Count() };
大概是吧
更多追问追答
追问
public List selectRole()
{
var query = from r in context.Role
order by r.RoleId
select new { r.RoleId,r.Role,ProNum = (from u in context.UserInfo select u where u.Role == r).Count() } ;
return query.toList();
}
query是什么结果集? List中的T应该换成什么对象?
追答
有三个属性:Roleid,Role,ProNum
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
from r in context.Role
order by r.RoleId
select new { r.RoleId,r.Role,ProNum = (from u in context.UserInfo select u where u.Role == r).Count() }
order by r.RoleId
select new { r.RoleId,r.Role,ProNum = (from u in context.UserInfo select u where u.Role == r).Count() }
更多追问追答
追问
public List selectRole()
{
var query = from r in context.Role
order by r.RoleId
select new { r.RoleId,r.Role,ProNum = (from u in context.UserInfo select u where u.Role == r).Count() } ;
return query.toList();
}
query是什么结果集? List中的T应该换成什么对象?
追答
匿名对象,你想要返回的话可以自己建一个对象,包含RoleId Role和ProNum属性
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询