You will need to create a simple class that takes the personal information of the registered students.
1 2 3 4 5 6 7 8 9 10 11 | public class Student { public int StudentID { get; set; } public string Name { get; set; } public string EmailAddress { get; set; } public string Department { get; set; } public Datetime DOB { get; set; } public string Gender { get ; set; } } |
The next step is to fill some dummy data and create a list of students that belongs to Computer Science department.
1 2 3 4 5 6 7 8 9 10 | public List GetStudents() { List Students = new List(); Students.Add(new Student { ID = 1, Name = "Student 1", EmailAddress = "Name1@abc.com" , Department = "ComputerScience " , DOB = "YYYY-MM-DD " , Gender = "Option A " }); Students.Add(new Student { ID = 2, Name = " Student 2", EmailAddress = "Name2@abc.com " , Department = "ComputerScience " , DOB = "YYYY-MM-DD " , Gender = "Option A " }); Students.Add(new Student { ID = 3, Name = " Student 3", EmailAddress = "Name3@abc.com " , Department = "ComputerScience " , DOB = "YYYY-MM-DD " , Gender = "Option B " }); Students.Add(new Student { ID = 4, Name = " Student 4", EmailAddress = "Name4@abc.com " , Department = "ComputerScience " , DOB = "YYYY-MM-DD " , Gender = "Option B" }); return Students; } |
If you call Contains() method in dbcontext class, it will mapped to the LIKE ‘%hello%’ operator automatically, and can perform the search by following the two ways:
1 2 3 4 5 | var results = _StudentRepository.GetPassedOutStudents .Where(p => p.Name.ToLower().Contains(GetStudents().Name.ToLower())) .ToList(); |
Alternatively, you can also do perform case insensitive comparison in this way:
1 2 3 4 5 6 | var lists = _StudentRepository.GetPassedOutStudents .Where(p => CultureInfo.CurrentCulture.CompareInfo.IndexOf (p.Name, GetStudents().Name, CompareOptions.IgnoreCase) >= 0) .ToList(); |