如何使用 linq 进行 LIKE 查询? [英] How to do a LIKE query with linq?

查看:122
本文介绍了如何使用 linq 进行 LIKE 查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

How can i perform an LIKE query within Linq?

I have the following query i would like to execute.

var results = from c in db.costumers
              where c.FullName LIKE "%"+FirstName+"%,"+LastName
              select c;

解决方案

You could use SqlMethods.Like(matchExpression,pattern)

var results = from c in db.costumers
              where SqlMethods.Like(c.FullName, "%"+FirstName+"%,"+LastName)
              select c;

The use of this method outside of LINQ to SQL will always throw a NotSupportedException exception.

这篇关于如何使用 linq 进行 LIKE 查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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