ENTITY FRAMEWORK - make a query like SQL type

0

Personal Speech,

I have a problem that may be not doing correctly, I have a query in a description field of a table eg

  

Select description table where field like 'test% description'

How do I do this with entity framework? because if I use the term Contains , it would make +/- as like '%teste descricao%' , but that's not what I want.

  Context.Item.Where(c=> c.descricao.Contains(termo)).toList();

Thanks for the help

Alex

    
asked by anonymous 24.10.2017 / 19:58

2 answers

1

I can not test here, but I think it might look like this:

Whereas you want the syntax for the same result as like 'teste%descricao' :

Context.Item.Where(c=> c.descricao.StartsWith("teste") && c.descricao.EndsWith("descricao")).toList();
    
24.10.2017 / 20:03
0

You can use StartWith, which would look like 'Test%' or EndWith, which would look like '% Test'. Here's an example:

Context.Item.Where(c=> c.descricao.StartsWith(termo)).toList();

Context.Item.Where(c=> c.descricao.EndsWith(termo)).toList();
    
24.10.2017 / 20:04