这是我的代码。我想将这个列表保存在一个会话变量中以供稍后进行身份验证(这是用户有权访问的对象列表....)我收到一个错误消息,说它不能将System.Collections.Generic.List隐式转换为“System”。 collections.Generic.List。帮帮我?将Linq查询转换为列表时出错
protected void Session_Start(object sender, EventArgs e)
{
string strUserName = User.Identity.Name;
string strShortUserName = strUserName.Replace("WINNTDOM\\", string.Empty).ToUpper();
System.Web.HttpContext.Current.Session["strShortUserName"] = strShortUserName;
System.Web.HttpContext.Current.Session["strUserName"] = strUserName;
List<string> authorizedObjects = new List<string>();
using (CPASEntities ctx = new CPASEntities())
{
var w = (from t in ctx.tblUsers
where (t.UserPassword == strUserName)
select t).FirstOrDefault();
if (!(w==null))
{
authorizedObjects = (from t in ctx.qryUserObjectAuthorization
where (t.UserPassword == strUserName)
select new { n = t.ObjectName }).ToList();
}
}
}
我删除了不必要的“新”条款,和它的工作。感谢您的期待。 – 2013-02-28 17:20:33