0

これが私のコードです。後で認証するためにリストをセッション変数に保存したい(これはユーザーがアクセスを許可されているオブジェクトのリストです...)System.Collections.Generic.Listを'Systemに暗黙的に変換できないというエラーが表示されます。 collections.Generic.List。ヘルプ?

    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();

            }
        }
    }
4

3 に答える 3

1

オブジェクトを初期化していList<string>ますが、別のオブジェクトにデータを入力しています。

List<string> authorizedObjects = new List<string>();

select new {  n = t.ObjectName, i = t.ObjectID } <--construct a class with these properties and initialize `List<WithNewClassName>`
于 2013-02-28T17:21:56.557 に答える
1

文字列のリストとしてそれを生成するには、

authorizedObjects = (from t in ctx.qryUserObjectAuthorization
                     where (t.UserPassword == strUserName)
                     select t.ObjectName).ToList();
于 2013-02-28T17:22:20.427 に答える
1

authorizedObjectsですList<string>が、匿名タイプのリストとして使用しようとしています。

List<string> authorizedObjects = new List<string>();

(...)

authorizedObjects = (from t in ctx.qryUserObjectAuthorization
                     where (t.UserPassword == strUserName)
                     select new {  n = t.ObjectName, i = t.ObjectID }).ToList()

クエリを次のように変更します。

authorizedObjects = (from t in ctx.qryUserObjectAuthorization
                     where (t.UserPassword == strUserName)
                     select t.ObjectName).ToList()
于 2013-02-28T17:20:18.397 に答える