Group by/count in LINQ against SQL Compact 3.5 SP2

Posted by bash74 on Stack Overflow See other posts from Stack Overflow or by bash74
Published on 2010-05-04T14:08:28Z Indexed on 2010/05/23 3:10 UTC
Read the original article Hit count: 324

Hello, I am using LINQ-To-Entities in C# and run queries against a SQL Compact Server 3.5 SP2. What I try to achieve is a simple group by with an additional where clause which includes a Count().

var baseIdent="expression";
var found=from o in ObservedElements

where o.ObservedRoots.BaseIdent==baseIdent group o by o.ID into grouped where grouped.Count()==1 select new {key=grouped.Key, val=grouped}; foreach(var res in found){ //do something here }

This query throws the famous exception "A parameter is not allowed in this location. Ensure that the '@' sign and all other parameters are in a valid location in the SQL statement."

When I either omit the where clause OR directly enter the expression "expression" in the query (where o.ObservedRoots.BaseIdent=="expression") everything just works fine.

Does anybody know how to solve this? Workaround would also be fine? Thanks in advance, Sebastian

© Stack Overflow or respective owner

Related posts about c#

Related posts about linq-to-entities