Linq To Sql: Contains any.

A

Andy

Hi,

I'm trying to figure out a linq to sql command that will execute
something similar to this sql:

select *
from products
where IsBundle = 0
AND (
productDescription like '%the%' OR
productDescription like '%january%' OR
productDescription like '%bobcat%'
)

I'm trying to do this:
var query = from products in db.Products select products;

if ( noBundles ) {
query = query.Where( p => p.IsBundle == false );
}

if ( descTokens.Count > 0 ) {
query = query.Where( p => descTokens.Any( s =>
p.Description.Contains( s ) ) );
}


But I'm getting the error Local sequence cannot be used in L2S
implementation except the Contains() operator.

Any ideas?
 
F

Frans Bouma [C# MVP]

Andy said:
Hi,

I'm trying to figure out a linq to sql command that will execute
something similar to this sql:

select *
from products
where IsBundle = 0
AND (
productDescription like '%the%' OR
productDescription like '%january%' OR
productDescription like '%bobcat%'
)

I'm trying to do this:
var query = from products in db.Products select products;

if ( noBundles ) {
query = query.Where( p => p.IsBundle == false );
}

if ( descTokens.Count > 0 ) {
query = query.Where( p => descTokens.Any( s =>
p.Description.Contains( s ) ) );
}


But I'm getting the error Local sequence cannot be used in L2S
implementation except the Contains() operator.

You've to add per fragment in s a Contains predicate.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top