public List <ShopViewModel> SearchShops(ShopCriteria shopCriteria) { var shopPred = PredicateBuilder.New <ZY_Shop>(true); if (shopCriteria.Status.HasValue) { shopPred = shopPred.And(x => x.ShopStatus == shopCriteria.Status.Value); } if (!string.IsNullOrEmpty(shopCriteria.ShopName)) { shopPred = shopPred.And(x => x.Name.Contains(shopCriteria.ShopName)); } var userPred = PredicateBuilder.New <T_S_User>(true); if (!string.IsNullOrEmpty(shopCriteria.OwnerName)) { userPred = userPred.And(x => x.LoginName.Contains(shopCriteria.OwnerName)); } using (var db = GetDbContext()) { var query = from s in db.ZY_Shop.AsExpandable().Where(shopPred) join u in db.T_S_User.AsExpandable().Where(userPred) on s.OwnId equals u.UserId select new ShopViewModel() { ShopId = s.ShopId, ShopName = s.Name, ShopStatus = s.ShopStatus, ShopAddress = s.Address, Owner = u.LoginName }; return(query.ToList()); } }
public ActionResult LoadShops(ShopCriteria condition) { var shops = BS.SearchShops(condition); return(new JsonResult() { Data = shops }); }