views:

35

answers:

1

I have the following compiled query that I want to return a list of "groups" that don't have a "GroupID" that's contained in a filtered list:

CompiledQuery.Compile(ConfigEntities contexty, List<int> list) =>
    from c in context.Groups
    where (!csList.Contains(c.GroupID))
    select c).ToList()

However I'm getting the following run-time error:

The specified parameter 'categories' of type 'System.Collections.Generic.List`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c261364e126]]' is not valid. Only scalar parameters (such as Int32, Decimal, and Guid) are supported.

Any ideas?

+1  A: 

This query will work fine in EF 4.

In EF 1, IEnumerable.Contains isn't supported in L2E (with or without CompiledQuery). There is a workaround, though; Google "BuildContainsExpression`.

Craig Stuntz
Yeah just been having a look at that as well, but I'm still getting the same error message. Any ideas why?
JK
If it's *exactly* the same message, then you're not using EF 4. If it's a different message, then post it and the actual query you're using. The message you posted doesn't actually conform to the query in your question, so I suspect there's some editing going on.
Craig Stuntz
Wait; i need to use EF4 for the BuildsContainsExpression?Exact query is: _compiledRefreshListGraphQuery = CompiledQuery.Compile((DASConfigEntities context, List<int> cSList) => context.Groups. Where(ObjectQueryExt.BuildContainsExpression<Group, int>(e => e.GroupID, cSList)));
JK
Other way around. EF 4 doesn't require `BuildContainsExpression` at all. It's only needed in EF 1.
Craig Stuntz
Yeah so I'm using EF1, with the BuildContainsExpression (copied and pasted) with the precompiled query as above - but I'm getting exactly the same error message.
JK
Then you're not using it correctly. Build the expression first, then do `.Where(builtExpression)`
Craig Stuntz
How would that be possible with pre-compiled queries though?The precompiled query takes cSList, as does the BuildContainsExpression. Perhaps it's time just to use 4.0
JK