public List<DishDetail> queryByDishDetail(DishDetail detail) { List<DishDetail> result; using (ChooseDishesEntities entities = new ChooseDishesEntities()) { //查询条件 Expression<Func<DishDetail, bool>> checkCourse = DishDetail => DishDetail.DishDaoId == detail.DishDaoId && DishDetail.Deleted == 0; result = entities.DishDetail.Include(t => t.Dish).Include(t => t.DishDao).Include(t => t.Dish.DishPrice).Include(t => t.Dish.DishUnit).Where(checkCourse).ToList(); } return result; }
public DishDetail CreateDishDetail(DishDetailBean bean) { DishDetail beanBack = new DishDetail(); beanBack.DishDetailId = bean.DishDetailId; beanBack.DishId = bean.DishId; beanBack.DishDaoId = bean.DishDaoId; beanBack.Num = bean.Num; beanBack.IsMain = bean.IsMain; beanBack.Type = bean.Type; beanBack.CreateDatetime = bean.CreateDatetime; beanBack.CreateBy = bean.CreateBy; beanBack.Deleted = bean.Deleted; beanBack.Status = bean.Status; beanBack.UpdateDatetime = bean.UpdateDatetime; beanBack.UpdateBy = bean.UpdateBy; return beanBack; }
public int EditByDishDetail(DishDetail dish) { int flag = 0; using (ChooseDishesEntities entities = new ChooseDishesEntities()) { //查询道菜是否存在 var type = entities.DishDetail.SingleOrDefault(bt => bt.DishDetailId == dish.DishDetailId && bt.Deleted == 0); if (type != null) { //设置属性是否参与修改 ,设置为false则无法更新数据 type.Num = dish.Num; type.IsMain = dish.IsMain; type.UpdateDatetime = dish.UpdateDatetime; type.UpdateBy = dish.UpdateBy; try { //关闭实体验证,不关闭验证需要整个对象全部传值 entities.Configuration.ValidateOnSaveEnabled = false; //操作数据库 flag = entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = true; } catch (Exception ex) { ex.ToString(); } } else { //实体绑定MODEL entities.DishDetail.Add(dish); try { //操作数据库 entities.Configuration.ValidateOnSaveEnabled = false; flag = entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = true; } catch (Exception ex) { ex.ToString(); } } } return flag; }
public DishDetailBean CreateDishDetailBean(DishDetail bean) { this.DishDetailId = bean.DishDetailId; this.DishId = bean.DishId; this.DishDaoId = bean.DishDaoId; this.Num = bean.Num; this.IsMain = bean.IsMain; this.Type = bean.Type; this.CreateDatetime = bean.CreateDatetime; this.CreateBy = bean.CreateBy; this.Deleted = bean.Deleted; this.Status = bean.Status; this.UpdateDatetime = bean.UpdateDatetime; this.UpdateBy = bean.UpdateBy; return this; }