LINQ2SQL LIKE Command for Phrase

后端 未结 3 1184
傲寒
傲寒 2020-12-20 17:47

I am trying to retrieve a list of string where it contains \"Britney Spears\", and this is what I use

from p in Objects
where p.Title.Contains(\"Britney Spea         


        
3条回答
  •  生来不讨喜
    2020-12-20 18:12

    Just use StartsWith() and EndsWith() to simulate the pattern. AFAIK, LINQ-to-SQL doesn't support wildcards.

    from p in Objects
    where p.Title.StartsWith("Britney") && c.Title.EndsWith("Spears")
    select p;
    

    Otherwise you could execute a query directly if you have a more complex pattern.

    db.ExecuteQuery("SELECT * "
                            + "FROM Objects "
                            + "WHERE Title LIKE 'Britney%Spears'");
    

提交回复
热议问题