Can someone convert the following simple SQL statement into LINQ? The StudentID is of type int.
select * from Student where studentId like '%1001%';
Thank you!
Can someone convert the following simple SQL statement into LINQ? The StudentID is of type int.
select * from Student where studentId like '%1001%';
Thank you!
ctx.Student.Where(x => x.StudentId.Contains("1001"))
It's strange that you have an ID of string type. Use int instead.
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"))
Try this:
db.Students.Where(s => s.StudentID.ToString().Contains("1001"))
Use the Contains operator:
from s in Student
where s.studentId.ToString().Contains("1001")
select s;