Linq to Entities (EF 4.1): How to do a SQL LIKE with a wildcard in the middle ( '%term%term%')?

后端 未结 3 1564
陌清茗
陌清茗 2021-01-01 16:04

I want to search for this:

Post Cereal

and get this:

Post Honey Nut Cereal

where the wild cards would be

3条回答
  •  旧时难觅i
    2021-01-01 16:15

    It is probably easier to bypass LINQ and use an Entity SQL filter:

    var query - db.table.Where("TRIM(fieldname) LIKE @pattern");
    query.Parameters.Add(new ObjectParameter("pattern", term)); // term == "%what%ever%"
    

    and the type of query implements IQueryable so you can apply further LINQ operators.

提交回复
热议问题