This is a migrated thread and some comments may be shown as answers.

Group By with substring throws an error

1 Answer 54 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Frank Schürer
Top achievements
Rank 1
Frank Schürer asked on 01 Sep 2010, 10:34 AM
Hi,

i have this code snippet here and i try to get it working...

Dim  Result = (From s In scope.Extent(Of ZipCodes)() _
          Where s.Coord = sValue _
          Group s By s.ZipCode.Substring(0, 2), s.Coord Into g = Group _
          Select  New  With  {.Region = ZipCode.Substring(0, 2), Coord})

The interpreter says the following:
Range variable name can be inferred only from a simple or qualified name with no arguments
Has anybody came across this issue?

1 Answer, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 03 Sep 2010, 03:20 PM
Hello Frank Schürer,

It seems that you usually get such an error when you have not given a name to some expression.
If you write the query like in the bellow snipped the error disappears:
Dim Result = From s In zipCodes _
            Where s.Coord = "coord" _
            Group s By start = s.Name.Substring(0, 2), s.Coord Into Group _
            Select New With {.Region = start}
Notice that the Substring expression is assigned to the start variable.
You can take a look at the following blog post for more information:
http://thedatafarm.com/blog/data-access/a-few-things-you-can-t-do-with-ef-queries-which-you-won-t-find-out-until-runtime/

Sincerely yours,
Jordan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
LINQ (LINQ specific questions)
Asked by
Frank Schürer
Top achievements
Rank 1
Answers by
Jordan
Telerik team
Share this question
or