Linq LIKE functionality

2019-02-24 07:12发布

so.. I'm using LinqToEntities, and I want to query part of a field. Normally I'd use the LIKE keyword with SQL, and then go from there..

I see that Linq does not have it.. Whats a good way to get the same kind of functionality?

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-02-24 07:50

You can use String.StartsWith() or String.Contains().

For example:

var query = from b in db.Books
            where b.Title.Contains("time")
            select b;

This works because LINQ turns the query into an expression tree, and for LINQ to SQL/Entities, many "standard" C# methods are supported for the conversion to SQL.

查看更多
登录 后发表回答