Wednesday 27 July 2016

Like operator in Linq using c#.



There are following ways to achieve like operator in Linq


1.)   Using StartsWith :- 
       var studentList = from s in Students where s.Stud_sname.StartsWith("M") select s 

2.)   Using EndsWith :- 
      var studentList = from s in Journals where s.Stud_sname.EndsWith("T") select s

 3.)   Using SqlMethods :- 
      For this use have to use System.Data.SqlClient namespace
     Var studentList = from m in Journals where   SqlMethods.Like(s.Stud_sname,"Ram%") select   s

  4.)   Using Contains :- 
      var studentList = from s in Journals where s.Stud_sname.Contains("Ram") select m

No comments:

Post a Comment

Note: only a member of this blog may post a comment.