简体   繁体   English

在LINQ中将字符串拆分为实体

[英]String split in LINQ to Entities

I have a table that contains a list of pagehits that I would like to analyse. 我有一张表格,其中包含我要分析的网页点击量列表。 One of the fields is URL that unsurprisingly contains the URL of the pagehit. 字段之一是URL ,它毫不奇怪地包含pagehit的URL。 This includes any query strings, eg http://foo.bar/default.aspx?test=1234 这包括任何查询字符串,例如http://foo.bar/default.aspx?test=1234

I would like to strip out the query strings from this table for my analysis and thought the following simple string split would work: 我想从该表中删除查询字符串以进行分析,并认为以下简单的字符串拆分将起作用:

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

However I get the error: The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities. 但是我得到了错误: The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities.

Given the table is fairly hefty whats the best way to return the URL without the query strings? 鉴于表相当繁重,在没有查询字符串的情况下返回URL的最佳方法是什么?

EDIT: I can get it work if i call .ToList but that seems computationally excessive 编辑:如果我调用.ToList ,我可以使它工作,但是在计算上似乎过多

You can try something like this 您可以尝试这样的事情

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

I made a List of strings which contains urls only to check if it works (my "list" in the code) 我制作了一个包含URL的字符串列表,仅用于检查它是否有效(代码中的“列表”)

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM