tags:

views:

52

answers:

3

How I can use Like query in LINQ .... in sql for eg..

name like='apple';

thanks..

A: 

name.contains("apple");

geoff
+3  A: 

Use normal .NET methods. For example:

var query = from person in people
            where person.Name.StartsWith("apple") // equivalent to LIKE 'apple%'
            select person;

(Or EndsWith, or Contains.) LINQ to SQL will translate these into the appropriate SQL.

This will work in dot notation as well - there's nothing magic about query expressions:

// Will find New York
var query = cities.Where(city => city.Name.EndsWith("York"));
Jon Skeet
+5  A: 

You need to use StartsWith, Contains or EndsWith depending on where your string can appear. For example:

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

will find all cities that start with "Lo" (e.g. London).

var query = from c in ctx.Customers
            where c.City.Contains("York")
            select c;

will find all cities that contain "York" (e.g. New York, Yorktown)

Source

ChrisF