/// <summary> /// 把实体类转换成键/值对集合 /// </summary> /// <param name="entity"></param> /// <param name="dict"></param> private static void GetParameters(SpecialCategoryEntity entity, Dictionary <string, object> dict) { dict.Add("SpecialCategoryID", entity.SpecialCategoryID); dict.Add("SpecialCategoryName", entity.SpecialCategoryName); dict.Add("SpecialCategoryDir", entity.SpecialCategoryDir); dict.Add("SpecialTemplatePath", entity.SpecialTemplatePath); dict.Add("OrderSort", entity.OrderSort); dict.Add("IsNewOpen", entity.IsNewOpen); dict.Add("Description", entity.Description); dict.Add("IsCreateHtml", entity.IsCreateHtml); dict.Add("PagePostfix", entity.PagePostfix); dict.Add("SearchTemplatePath", entity.SearchTemplatePath); dict.Add("IsNeedCreateHtml", entity.IsNeedCreateHtml); }
/// <summary> /// 获取实体(异步方式) /// </summary> /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param> /// <param name="dict">参数的名/值集合</param> /// <returns></returns> public virtual async Task <SpecialCategoryEntity> GetEntityAsync(string strWhere, Dictionary <string, object> dict = null) { SpecialCategoryEntity obj = null; string strSQL = "select top 1 * from SpecialCategory where 1=1 " + strWhere; using (NullableDataReader reader = await Task.Run(() => _DB.GetDataReader(strSQL, dict))) { if (reader.Read()) { obj = GetEntityFromrdr(reader); } } return(obj); }
/// <summary> /// 通过数据读取器生成实体类 /// </summary> /// <param name="rdr"></param> /// <returns></returns> private static SpecialCategoryEntity GetEntityFromrdr(NullableDataReader rdr) { SpecialCategoryEntity info = new SpecialCategoryEntity(); info.SpecialCategoryID = rdr.GetInt32("SpecialCategoryID"); info.SpecialCategoryName = rdr.GetString("SpecialCategoryName"); info.SpecialCategoryDir = rdr.GetString("SpecialCategoryDir"); info.SpecialTemplatePath = rdr.GetString("SpecialTemplatePath"); info.OrderSort = rdr.GetInt32("OrderSort"); info.IsNewOpen = rdr.GetBoolean("IsNewOpen"); info.Description = rdr.GetString("Description"); info.IsCreateHtml = rdr.GetBoolean("IsCreateHtml"); info.PagePostfix = rdr.GetString("PagePostfix"); info.SearchTemplatePath = rdr.GetString("SearchTemplatePath"); info.IsNeedCreateHtml = rdr.GetBoolean("IsNeedCreateHtml"); return(info); }
/// <summary> /// 增加一条记录,返回新的ID号。需要有一个单一主键,并且开启有标识符属性(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual async Task <int> InsertAsync(SpecialCategoryEntity entity) { if (entity.SpecialCategoryID <= 0) { entity.SpecialCategoryID = GetNewID(); } Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "insert into SpecialCategory (" + "SpecialCategoryID," + "SpecialCategoryName," + "SpecialCategoryDir," + "SpecialTemplatePath," + "OrderSort," + "IsNewOpen," + "Description," + "IsCreateHtml," + "PagePostfix," + "SearchTemplatePath," + "IsNeedCreateHtml) " + "values(" + "@SpecialCategoryID," + "@SpecialCategoryName," + "@SpecialCategoryDir," + "@SpecialTemplatePath," + "@OrderSort," + "@IsNewOpen," + "@Description," + "@IsCreateHtml," + "@PagePostfix," + "@SearchTemplatePath," + "@IsNeedCreateHtml)"; if (await Task.Run(() => _DB.ExeSQLResult(strSQL, dict))) { return(DataConverter.CLng(entity.SpecialCategoryID)); } return(-1); }
/// <summary> /// 更新一条记录(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual async Task <bool> UpdateAsync(SpecialCategoryEntity entity) { Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "Update SpecialCategory SET " + "SpecialCategoryName = @SpecialCategoryName," + "SpecialCategoryDir = @SpecialCategoryDir," + "SpecialTemplatePath = @SpecialTemplatePath," + "OrderSort = @OrderSort," + "IsNewOpen = @IsNewOpen," + "Description = @Description," + "IsCreateHtml = @IsCreateHtml," + "PagePostfix = @PagePostfix," + "SearchTemplatePath = @SearchTemplatePath," + "IsNeedCreateHtml = @IsNeedCreateHtml" + " WHERE " + "SpecialCategoryID = @SpecialCategoryID"; return(await Task.Run(() => _DB.ExeSQLResult(strSQL, dict))); }
/// <summary> /// 增加一条记录 /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual bool Add(SpecialCategoryEntity entity) { if (entity.SpecialCategoryID <= 0) { entity.SpecialCategoryID = GetNewID(); } Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "insert into SpecialCategory (" + "SpecialCategoryID," + "SpecialCategoryName," + "SpecialCategoryDir," + "SpecialTemplatePath," + "OrderSort," + "IsNewOpen," + "Description," + "IsCreateHtml," + "PagePostfix," + "SearchTemplatePath," + "IsNeedCreateHtml) " + "values(" + "@SpecialCategoryID," + "@SpecialCategoryName," + "@SpecialCategoryDir," + "@SpecialTemplatePath," + "@OrderSort," + "@IsNewOpen," + "@Description," + "@IsCreateHtml," + "@PagePostfix," + "@SearchTemplatePath," + "@IsNeedCreateHtml)"; return(_DB.ExeSQLResult(strSQL, dict)); }
/// <summary> /// 增加或更新一条记录(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <param name="IsSave">是否增加</param> /// <returns></returns> public virtual async Task <bool> AddOrUpdateAsync(SpecialCategoryEntity entity, bool IsSave) { return(IsSave ? await AddAsync(entity) : await UpdateAsync(entity)); }
/// <summary> /// 增加或更新一条记录 /// </summary> /// <param name="entity">实体模型</param> /// <param name="IsSave">是否增加</param> /// <returns></returns> public virtual bool AddOrUpdate(SpecialCategoryEntity entity, bool IsSave) { return(IsSave ? Add(entity) : Update(entity)); }