How to do SQL Like % in Linq?

前端 未结 14 1510
误落风尘
误落风尘 2020-11-22 13:46

I have a procedure in SQL that I am trying to turn into Linq:

SELECT O.Id, O.Name as Organization
FROM Organizations O
JOIN OrganizationsHierarchy OH ON O.Id         


        
14条回答
  •  孤街浪徒
    2020-11-22 14:20

    Use such code

    try
    {
        using (DatosDataContext dtc = new DatosDataContext())
        {
            var query = from pe in dtc.Personal_Hgo
                        where SqlMethods.Like(pe.nombre, "%" + txtNombre.Text + "%")
                        select new
                        {
                            pe.numero
                            ,
                            pe.nombre
                        };
            dgvDatos.DataSource = query.ToList();
        }
    }
    catch (Exception ex)
    {
        string mensaje = ex.Message;
    }
    

提交回复
热议问题