2014-02-25 186 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]; 
            });