I use criteria classes for search database in ado.net. For example, for searcing Users in db, I use UserSearchCriteria class to search with operands like "like", "between", "greater than", "less than"... For example search Username contains, DisableCount greater than and Id exact match so on.
Currently Search function call :
var users = userManager.Search(new UserSearchCriteria() { Id = new
Dictionary<int,OperandTypeEnum>(1,OperandTypeEnum.ExactMatch),
Username = new Dictionary<string, OperandTypeEnum>("John Doe",OperandTypeEnum.Like),
DisableCount = new Dictionary<int, OperandTypeEnum>(5,OperandTypeEnum.GreaterThan)});
The question is that, is there a better option to search with operands? Because simplified calling search function would be better.
public enum OperandTypeEnum
{
ExactMatch=0, // default
Like,
GreaterThan,
LessThan,
Between
}
public class UserSearchCriteria
{
public Dictionary<int?,OperandTypeEnum> Id { get; set; }
public Dictionary<string, OperandTypeEnum> Username { get; set; }
public Dictionary<int, OperandTypeEnum> DisableCount { get; set; }
}