我有一种感觉,还支持使用连接可以使这种清洁如何使用连接使此查询更清洁?
public override string[] GetRolesForUser(string username)
{
using (TemplateEntities ctx = new TemplateEntities())
{
using (TransactionScope tran = new TransactionScope())
{
int userId = (from u in ctx.Users
where u.UserName == username
select u.UserId).Single();
int[] roleIds = (from ur in ctx.UserInRoles
where ur.UserId == userId
select ur.RoleId).ToArray();
string[] roleNames = (from r in ctx.Roles
where roleIds.Contains(r.RoleId)
select r.RoleName).ToArray();
tran.Complete();
return roleNames;
}
}
}
如果您发布代码或XML,请**在文本编辑器中高亮显示这些行,然后单击编辑器工具栏上的“代码”按钮(101 010)以很好的格式和语法突出显示它! – 2010-10-22 21:13:32