我有一些设置用户属性的代码,如下所示:
us = new UserSession();
us.EmailAddr = emailAddr;
us.FullName = fullName;
us.UserROB = GetUserROB(uprUserName);
us.UserID = GetUserID(uprUserName);
us.UserActive = GetUserActive(uprUserName);
whereGetUserROB
和所有看起来都像这样GetUserID
:GetUserActive
private static string GetUserActive(string userName)
{
using (Entities ctx = CommonSERT.GetContext())
{
var result = (from ur in ctx.datUserRoles
where ur.AccountName.Equals(userName, StringComparison.CurrentCultureIgnoreCase)
select new
{
Active = ur.active
}).FirstOrDefault();
if (result != null)
return result.Active;
else
return "N";
}
}
它有效,但我认为这不是正确的方法。如何在一次 LINQ 调用中分配 userROB、ID 和 Active 属性?不必有 3 个单独的功能来做到这一点?