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. This includes any query strings, e.g. 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.

Given the table is fairly hefty whats the best way to return the URL without the query strings?

EDIT: I can get it work if i call .ToList but that seems computationally excessive

Answers


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)


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

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

Need Your Help

How to add satellite assemblies to a project in Visual Studio

visual-studio localization satellite-assembly

I'm working in a project which references assemblies from a third company. These assemblies have satellite assemblies that I'm copying with a post-build event to the bin folder.

The project was not built

java android eclipse project target

I am unable to resolve the error below.