LINQ一样的功能 [英] Linq LIKE functionality

查看:107
本文介绍了LINQ一样的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以..我使用LinqToEntities,我要查询的字段的一部分。通常情况下我会使用与SQL LIKE关键字,然后从那里..

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..

我看到LINQ的没有它..请告诉我一个很好的方式来获得同样的功能?

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

推荐答案

您可以使用的 String.StartsWith() 或的 String.Contains()

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

例如:

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

这工作,因为原来LINQ查询到的表达式树,和的LINQ to SQL /实体,很多标准C#方法都支持转换为SQL。

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.

这篇关于LINQ一样的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆