2012-04-30 52 views
-2

我正在一個錯誤在這行代碼Session.Linq<Employees>()對象引用不設置爲一個對象的一個​​實例在會話

「的對象引用需要非靜態字段,方法或屬性」 System.Web.UI.Page.Session.get」

這是我的代碼:

public static object GetData(Dictionary<string, object> tableParams) 
     { 
      IQueryable<Employees> Employee = Session.Linq<Employees>(); 
      if (tableParams.ContainsKey("sEcho")) 
      { 
       var parser = new DataTableParser<Employees>(tableParams, Employee); 
       return parser.Parse(); 
      } 
      return Employee; 
     } 

如果我使用HttpContext.Current.Session.Linq<Employees>(); 然後灌胃等:

「System.Web.SessionState.HttpSessionState」不包含關於「的LINQ」的定義和沒有擴展方法「的LINQ」接受類型「System.Web.SessionState.HttpSessionState」的第一個參數可以是發現'

我需要做些什麼才能使這個工作?我是否缺少Linq關於Session的命名空間?我正在使用System.LinqSystem.Linq.Expression

+0

什麼是'Linq的()'? – jrummell

+1

@ jrummell有點像'Cup ' – mattytommo

回答

0

我認爲你誤解了一些東西。你試圖做的事情與Linq沒有任何關係,至少在沒有從會話中檢索對象的情況下。

您需要從會議檢索對象和拆箱它:

var list = Session["MyList"] as List<int>; 
if (list != null) 
{ 
    //the list was found and you can start using it here 
} 
相關問題