1.简单查询
2.多表查询
3.高级查询
public List<User> GetUsers(string companyID, string userName, int skip, int limit) { var dc = new DbContext(); var query = (from c in dc.Users join d in dc.UserRoles on c.Id equals d.UserId join e in dc.Roles on d.RoleId equals e.Id where c.CompanyId == companyID && c.IsDeleted == false && (string.IsNullOrWhiteSpace(userName) ? true : c.UserName.Contains(userName)) orderby c.Id select new { Id = c.Id, UserName = c.UserName, RoleName = e.Name }).Skip(skip).Take(limit).ToList() .Select(x => new User { Id = x.Id, UserName = x.UserName, RoleName = x.RoleName }).ToList(); return query; }
这个查询是一个包含了条件过滤、分页、多表、转换为实体列表的综合查询,缺点是条件过滤无法动态化