You must Sign In to post a response.
  • Category: LINQ

    Need a equivalent query in LINQ

    Hi,

    SELECT *
    FROM hp_client
    WHERE c_clt_id LIKE '%132%'

    Where c_clt_id is an integer column.

    I need an equivalent query in LINQ.

    Thanks in advance.
  • #577981
    Should be like:
    var Client = from o in hp_client
    where o.c_clt_id LIKE '%132%'
    select * ;
    and please let me know if it is not correct

    Thanks and Regards
    Vikas

  • #577997
    Hi Vkias,

    Their is no keyword "like" in LINQ.

    We have contains method which works exactly like "like". but it works only on string data type.


    Thanks & Regards


    Bunty

  • #578147
    Using Extension Methods we have this solution.
    var clients=db.hp_clients
    .SelectMany(p=>p.c_clt_id.Contains('132'));
    foreach(var d in clients)
    {
    Response.Write(d.c_clt_id.ToString());
    }
    With Standard Query Operators we have this solution,
    var clients=from c in db.hp_clients
    where c.c_clt_id.Contains('132')
    select c;
    foreach(var f in clients)
    {
    Response.Write(f.c_clt_id.ToString());
    }

  • #579636
    u can use the following statement

    var q = from c in db.Customers
    where SqlMethods.Like(c.CustomerID, "C%")
    select c;


    jagan

  • #581109
    var result= from hp in db.hp_client
    where
    hp.c_clt_id.Contains("132")
    select new
    {
    hp.column0,
    hp.column1,
    hp.column2,
    .....
    .....
    }

  • #588242
    Hi

    You may try this one



    var a = from c in Customers
    where SqlMethods.Like(c.Name, "%A%Z")
    select c;

    // generates WHERE name LIKE '%A%Z';
    return view(a)

  • #588790
    var result=from c in db.hp_client
    where SqlMethods.Like(c.c_clt_id,'%132%')
    select c;


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.