Sometimes, we have requirement like need to pass one parameter but its nullable, and we have to pass this parameter in where clause also need to check only if value is not null then only check condition..then in this case what we can do ..???
well here is one of the solution :
public employee GetEmployee(int id, string appId)
{
var result= (from e in objcontext.employee
where e.Id==id &&
(string.IsNullOrEmpty(appId) || e.AppId==appId)
// Here it will check first if null then it will not go to second condition else it will check where clause for that column
select e).ToList();
}
well here is one of the solution :
public employee GetEmployee(int id, string appId)
{
var result= (from e in objcontext.employee
where e.Id==id &&
(string.IsNullOrEmpty(appId) || e.AppId==appId)
// Here it will check first if null then it will not go to second condition else it will check where clause for that column
select e).ToList();
}
No comments:
Post a Comment