Is there an equivalent of System.Data.Linq.SqlClient.SqlMethods.Like or the FieldLikePredicate?

Posts   
 
    
TomDog
User
Posts: 623
Joined: 25-Oct-2005
# Posted on: 02-Sep-2008 05:03:06   

I couldn't spot it in the help file but is there a way of doing more complicated LIKE's then offered by Contains, StartsWith or EndsWith? See http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/10/16/linq-to-sql-like-operator.aspx

Jeremy Thomas
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Sep-2008 06:09:19   

Could you please post some example of what are you trying to achieve?

David Elizondo | LLBLGen Support Team
TomDog
User
Posts: 623
Joined: 25-Oct-2005
# Posted on: 02-Sep-2008 06:32:04   

daelmo wrote:

Could you please post some example of what are you trying to achieve?

I'm not trying to achieve anything - just want to know if the example in the link can be done.

Jeremy Thomas
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Sep-2008 07:05:53   

Oh, I see simple_smile Sure, you can do that. See these examples:

StartsWith

var q = from c in metaData.Customer
        where c.Country.StartsWith("A")
        select c;

EndsWith

var q = from c in metaData.Customer
        where c.Country.EndsWith("A")
        select c;

Contains

var q = from o in metaData.Order
        where o.Customer.Country.Contains("land")
        select o;

Like

var query = from c in ctx.Customers
            where SqlMethods.Like(c.City, "L_n%")
            select c;

above (LINQ2SQL) is the same to (LINQ2LLBL):

var query = from c in metaData.Customers
            where c.City.StartsWith("L_n")
            select c;

You can find some examples at [LLBLGenPro intallation folder]\Sourcecode\LinqUnitTests\AdapterTests

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39888
Joined: 17-Aug-2003
# Posted on: 02-Sep-2008 10:17:24   

Indeed, StartsWith/EndsWith/Contains are the 3 methods to use for Like operator behavior. If you want, you can also map a different method to LIKE in your own functionmappings simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Prashant
User
Posts: 2
Joined: 03-May-2014
# Posted on: 03-May-2014 23:29:39   

I am using following line of Code

        var colContent = from content in metaData.Content
                             where SqlMethods.Like(content.TitleBrief, "Men%")
                             select content;

I am geeting an Error

The binary expression '(Like(EntityField(LPLA_1.TitleBrief AS TitleBrief), "Men%") == True)' can't be converted to a predicate expression.

Am i doing something wrong

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39888
Joined: 17-Aug-2003
# Posted on: 04-May-2014 11:31:49   

Answered in other thread with same message.

Please don't re-open old threads.

Frans Bouma | Lead developer LLBLGen Pro