Convert SQL Query into LINQ Expression - LIKE operator on integer?

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 doesn't make sense.

You must convert int to string first ctx.Student. Where(x => x.StudentId.ToString(). Contains("1001")).

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 doesn't make sense.

You must convert int to string first. Ctx.Student. Where(x => x.StudentId.ToString().

Contains("1001")).

It works! I tried this before and it did not work because I forgot to use quotes in "1001". Thank you so much for your quick response.

– rk1962 Jun 23 at 22:01.

Thank you Keith! – rk1962 Jun 23 at 22:07.

Use the Contains operator: from s in Student where s.studentId.ToString(). Contains("1001") select s.

It is giving the following error: 'int' does not contain a definition for 'Contains' and the best extension method overload 'System.Linq.Queryable. Contains(System.Linq. IQueryable, TSource)' has some invalid arguments – rk1962 Jun 23 at 21:51 Change it to: where s.studentId.ToString().

Contains("1001") I was assuming since you were comparing a column to a string in your original query that the column itself was a string. Honestly, this sort of query goes against what I would consider good programming practices with regards to the use of primary keys; it makes me think that there may be a better way to accomplish what you want that will give you less headaches down the road. You may want to investigate.

– Lucent Fox Jun 23 at 22:02 Just reread the OP and noticed that it stated that it was an int, my bad. – Lucent Fox Jun 23 at 22:04 Actually, the StudentID column is of type int. I wanted to return all rows that matches 1001.

I belive this is the only simple way you can retrieve all rows that contains 1001. Let me know if my understanding is wrong. Thank you!

– rk1962 Jun 23 at 22:06.

In that case you cannot use like in SQL. It doesn't make sense. You must convert int to string first.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions