///<summary> ///向数据库中添加一条记录 ///</summary> ///<param name="model">要添加的实体</param> public bool Insert(TbkItem model) { const string sql = @"INSERT INTO [dbo].[TbkItem] (num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,nick,seller_id,volume) VALUES (@num_iid,@title,@pict_url,@small_images,@reserve_price,@zk_final_price,@user_type,@provcity,@item_url,@nick,@seller_id,@volume)"; int res = SqlHelper.ExecuteNonQuery(sql, new SqlParameter("@num_iid", model.num_iid.ToDBValue()), new SqlParameter("@title", model.title.ToDBValue()), new SqlParameter("@pict_url", model.pict_url.ToDBValue()), new SqlParameter("@small_images", model.small_images.ToDBValue()), new SqlParameter("@reserve_price", model.reserve_price.ToDBValue()), new SqlParameter("@zk_final_price", model.zk_final_price.ToDBValue()), new SqlParameter("@user_type", model.user_type.ToDBValue()), new SqlParameter("@provcity", model.provcity.ToDBValue()), new SqlParameter("@item_url", model.item_url.ToDBValue()), new SqlParameter("@nick", model.nick.ToDBValue()), new SqlParameter("@seller_id", model.seller_id.ToDBValue()), new SqlParameter("@volume", model.volume.ToDBValue())); return(res > 0); }
/// <summary> /// 查询单个模型实体 /// </summary> /// <param name="id">num_iid</param>); /// <returns>实体</returns>); public TbkItem QuerySingleById(long num_iid) { const string sql = "SELECT TOP 1 num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,nick,seller_id,volume from TbkItem WHERE [num_iid] = @num_iid"; using (var reader = SqlHelper.ExecuteReader(sql, new SqlParameter("@num_iid", num_iid))) { if (reader.HasRows) { reader.Read(); TbkItem model = SqlHelper.MapEntity <TbkItem>(reader); return(model); } else { return(null); } } }
///<summary> ///分页查询一个集合 ///</summary> ///<param name="index">页码</param> ///<param name="size">页大小</param> ///<param name="wheres">条件匿名类</param> ///<param name="orderField">排序字段</param> ///<param name="isDesc">是否降序排序</param> ///<returns>实体集合</returns> public IEnumerable <TbkItem> QueryList(int index, int size, object wheres = null, string orderField = "uuid", bool isDesc = true) { List <SqlParameter> list = null; string where = wheres.parseWheres(out list); orderField = string.IsNullOrEmpty(orderField) ? "uuid" : orderField; var sql = SqlHelper.GenerateQuerySql("TbkItem", new string[] { "num_iid", "title", "pict_url", "small_images", "reserve_price", "zk_final_price", "user_type", "provcity", "item_url", "nick", "seller_id", "volume" }, index, size, where, orderField, isDesc); using (var reader = SqlHelper.ExecuteReader(sql, list.ToArray())) { if (reader.HasRows) { while (reader.Read()) { TbkItem model = SqlHelper.MapEntity <TbkItem>(reader); yield return(model); } } } }
/// <summary> /// 根据主键更新一条记录 /// </summary> /// <param name="model">更新后的实体</param> /// <returns>执行结果受影响行数</returns> public bool Update(TbkItem model) { return(_dao.Update(model)); }
/// <summary> /// 向数据库中添加一条记录 /// </summary> /// <param name="model">要添加的实体</param> /// <returns>是否成功</returns> public bool Insert(TbkItem model) { return(_dao.Insert(model)); }
/// <summary> /// 根据主键更新一条记录 /// </summary> /// <param name="model">更新后的实体</param> /// <returns>是否成功</returns> public bool Update(TbkItem model) { const string sql = @"UPDATE [dbo].[TbkItem] SET title=@title,pict_url=@pict_url,small_images=@small_images,reserve_price=@reserve_price,zk_final_price=@zk_final_price,user_type=@user_type,provcity=@provcity,item_url=@item_url,nick=@nick,seller_id=@seller_id,volume=@volume WHERE [num_iid] = @num_iid"; return(SqlHelper.ExecuteNonQuery(sql, new SqlParameter("@num_iid", model.num_iid.ToDBValue()), new SqlParameter("@title", model.title.ToDBValue()), new SqlParameter("@pict_url", model.pict_url.ToDBValue()), new SqlParameter("@small_images", model.small_images.ToDBValue()), new SqlParameter("@reserve_price", model.reserve_price.ToDBValue()), new SqlParameter("@zk_final_price", model.zk_final_price.ToDBValue()), new SqlParameter("@user_type", model.user_type.ToDBValue()), new SqlParameter("@provcity", model.provcity.ToDBValue()), new SqlParameter("@item_url", model.item_url.ToDBValue()), new SqlParameter("@nick", model.nick.ToDBValue()), new SqlParameter("@seller_id", model.seller_id.ToDBValue()), new SqlParameter("@volume", model.volume.ToDBValue())) > 0); }