Linq To Sql: Contains any.

  • Thread starter Thread starter Andy
  • Start date Start date
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?
 
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#)
------------------------------------------------------------------------
 
Back
Top