2014-02-25 182 views
2

我有一張表,其中包含我想要分析的頁面列表。其中一個字段是URL,毫不意外包含pagehit的URL。這包括任何查詢字符串,例如http://foo.bar/default.aspx?test=1234將字符串拆分爲LINQ to Entities

我想去掉從該表的查詢字符串我的分析和思考以下簡單的字符串拆分將工作:

var pageHits = from p in context.Pagehits 
        let URL = p.URL.Split('?')[0] 
        select p; 

但是我得到的錯誤: The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities.

鑑於該表是相當沉重什麼是最好的方式來返回沒有查詢字符串的網址?

編輯: 我可以,如果我叫.ToList它的工作,但似乎計算過度

回答

1

你可以嘗試這樣的事情

   var pageHits = from p in list 
          select p.Substring(0,p.IndexOf('?'); 

我做字符串列表包含的URL只檢查如果它有效(我的「清單」在代碼中)

-2
   var pageHits = from p in context.Pagehits 
       select p; 

       pageHits.ToList().ForEach(p => 
            { 
            p.Url = p.Url.Split('?')[0]; 
            });