AsQueryable擴充套件方法的拼接查詢使用:
MyDbcontext _dbcontext=new MyDbcontext();
var query=_dbcontext.Users.AsQueryable();
if(!string.IsNullOrWhiteSpace(username))
{
query=query.Where(p=>p.UserName!.Contains(username));
}
if(!string.IsNullOrWhiteSpace(password))
{
query=query.Where(p=>p.Pwd!.Contains(password));
}
if(userId>0)
{
query=query.Where(p=>p.UserId==id);
}
var List_user=query.ToListAsync();