To
filter a table for specific rows we need to use Where clause and specify a
filter condition in the Where clause.
To get all employees who have Age > 30 we need to use the following LINQ Query
var Employees = _context.Employee.Where(e => e.Age > 30);
To get all employees with DepartmentId = 1 use the following LINQ Query
var Employees = _context.Employee.Where(e => e.DepartmentId == 1);
To get all employees whose Name contains rry use the following LINQ Query. This is similar to the LIKE clause in SQL Server Name LIKE ‘%rry%’
var Employee = _context.Employee.Where(e => e.Name.Contains("rry"));
To get all employees whose Name starts with T use the following LINQ Query. This is similar to the LIKE clause in SQL Server Name LIKE ‘T%’
var Employee = _context.Employee.Where(e => e.Name.StartsWith("T"));
To get all employees whose Name ends with n use the following LINQ Query. This is similar to the LIKE clause in SQL Server Name LIKE ‘%n’
var Employee = _context.Employee.Where(e => e.Name.EndsWith("n"));
To get all employees who have Age > 30 we need to use the following LINQ Query
var Employees = _context.Employee.Where(e => e.Age > 30);
To get all employees with DepartmentId = 1 use the following LINQ Query
var Employees = _context.Employee.Where(e => e.DepartmentId == 1);
To get all employees whose Name contains rry use the following LINQ Query. This is similar to the LIKE clause in SQL Server Name LIKE ‘%rry%’
var Employee = _context.Employee.Where(e => e.Name.Contains("rry"));
To get all employees whose Name starts with T use the following LINQ Query. This is similar to the LIKE clause in SQL Server Name LIKE ‘T%’
var Employee = _context.Employee.Where(e => e.Name.StartsWith("T"));
To get all employees whose Name ends with n use the following LINQ Query. This is similar to the LIKE clause in SQL Server Name LIKE ‘%n’
var Employee = _context.Employee.Where(e => e.Name.EndsWith("n"));
No comments:
Post a Comment