Does LINQ to Entities not recognize the 'Boolean Like?

0

I'm having this error when trying to do one with query using LINQ to SQL after making the suggested changes:

{SELECT
'Extent1'.'idcliente', 
'Extent1'.'nome', 
'Extent1'.'pai', 
'Extent1'.'mae', 
'Extent1'.'informacao', 
'Extent1'.'datanascimento', 
'Extent1'.'foto'
FROM 'cliente' AS 'Extent1'
 WHERE (LOCATE(TRIM(@p__linq__0), 'Extent1'.'mae')) = 1}

C #

    [HttpPost]
    public ActionResult Index(string recebeNome, int recebeOpcao)
    {


        try
        {
            sistema_mobileEntities dao = new sistema_mobileEntities();
            IQueryable<cliente> sql;
            sql = null;

            if (recebeOpcao == 1)
            {

                //link to sql não tem like
                sql = from c in dao.cliente
                      where c.nome.StartsWith(recebeNome.Trim())
                      // where SqlMethods.Like(c.nome, recebeNome.Trim() + "%")
                      select c;

                TempData["opcao1"] = "nome";
            }

            if (recebeOpcao == 2)
            {
                sql = from c in dao.cliente
                      where c.pai.StartsWith(recebeNome.Trim())
                      select c;

                TempData["opcao2"] = "pai";
            }

            if (recebeOpcao == 3)
            {
                sql = from c in dao.cliente
                      where c.mae.StartsWith(recebeNome.Trim())
                      select c;

                TempData["opcao3"] = "mae";
            }

            return View(sql.ToList());
        }

        catch (Exception ex)
        {
            return Json("Erro ao consultar cliente" + ex.Message);
        }


    }
    
asked by anonymous 06.04.2015 / 16:59

2 answers

2

If you were using LINQ To SQL you would need to ensure that you are using namespace with using System.Data.Linq.SqlClient . But in LINQ To Entities there is no such method. You would have to create a method that would simulate a LIKE or use another form.

In this specific case you could only use

where c.nome.StartsWith(recebeNome.Trim())
    
06.04.2015 / 17:10
0

Use SqlFunctions.PatIndex instead of SqlMethods.Like , if it is not available.

  • The SqlFunctions is set in assembly System.Data.Entity.dll

  • whereas the SqlMethods " is set in assembly System.Data.Linq.dll

06.04.2015 / 18:27