我有一種感覺,還支持使用連接可以使這種清潔如何使用連接使此查詢更清潔?
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