lambda 表达式 自定义查询

遇到 这样的 问题

常用 EF 。

 实现  like 用 Contains("asd")  搞定 他生成的是 %asd% .

如果 我希望 生成  asd%,怎么搞呢? StartsWith  搞定 ,%asd 当然是 EndsWith 搞定 。

如果 是 qwe%zz 怎么搞呢。哇哈哈~~~

using System.Linq;
using System.Data;
using System.Data.Objects;
using System.Data.Linq.SqlClient;

  var rr= from l  in db.UserInfo where   SqlMethods.Like("","") select l;

看 SqlMethods  可以搞定。 具体看SqlMethods   的解释吧。  但是 这是 linq 啊。  如果在 EF 中 就不行了,他会报错 LINQ to Entities 不识别方法“Boolean Like(System.String, System.String)”,因此该方法无法转换为存储表达式。

本次 说明下  System.Data.Linq  ,和System.Linq   是 两 回事。

 http://stackoverflow.com/  本人 第一次 接触 。很强大的平台 有各种解答。

首先 谢谢 群里的朋友 。

原文地址:https://www.cnblogs.com/bingguang/p/4492677.html