I faced scenario to add some specified where clause based some conditions, so that i have used following code. We can add any number of where conditions like below and execute query to RavenDB.
public IEnumerable<Student> SearchStudents()
{
List<Expression<Func<Student, bool>>> whereConditionList = new List<Expression<Func<Student, bool>>>();
whereConditionList.Add(p
=> p.Name == "Balajiprasad");
whereConditionList.Add(p
=> p.Age > 16);
whereConditionList.Add(p
=> p.City == "Coimbatore");
var ravenQuery = ravenSession.Query<Student>();
foreach (var condition in whereConditionList)
ravenQuery = ravenQuery.Where(condition);
return ravenQuery.ToList();
}
No comments:
Post a Comment