用户登录
用户注册

分享至

如何使用 linq 进行 LIKE 查询?

  • 作者: 擦肩而过31525709
  • 来源: 51数据库
  • 2022-12-08

问题描述

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.

软件
前端设计
程序设计
Java相关