将SQL查询转换为LINQ表达式-整数的LIKE运算符 [英] Convert SQL Query into LINQ Expression - LIKE operator on integer

查看:87
本文介绍了将SQL查询转换为LINQ表达式-整数的LIKE运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以将以下简单的SQL语句转换为LINQ吗? StudentID的类型为int.

Can someone convert the following simple SQL statement into LINQ? The StudentID is of type int.

从学生ID"为%1001%"的学生中选择*;

select * from Student where studentId like '%1001%';

谢谢!

推荐答案

 ctx.Student.Where(x => x.StudentId.Contains("1001"))

奇怪的是您有一个字符串类型的ID. 改用int.

It's strange that you have an ID of string type. Use int instead.

哦,对不起,我现在知道了,您写道id是整数.在这种情况下,您不能在SQL中使用like. 这没有道理.您必须先将int转换为字符串.

O, sorry, I see now, you wrote that ids are ints. In that case you cannot use like in SQL. It doesnt make sense. You must convert int to string first.

ctx.Student.Where(x => x.StudentId.ToString().Contains("1001"))

这篇关于将SQL查询转换为LINQ表达式-整数的LIKE运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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