/// <summary> /// 插入记录 /// </summary> /// <param name="param">ParamInsert</param> /// <returns></returns> public int Insert(ParamInsert param) { var result = 0; db.UseTransaction(true); var rtnBefore = this.OnBeforeInsert(new InsertEventArgs() { db = db, data = param.GetData() }); if (!rtnBefore) { return(result); } //var Identity = BaseEntity.GetAttributeFields<T, TableAttribute>(); var Identity = AttributeHelper.GetCustomAttribute <TableAttribute>(typeof(T)).IdentityField; result = Identity != "" ? BuilderParse(param).ExecuteReturnLastId <int>() : BuilderParse(param).Execute(); this.CommandResult.Set(true, APP.Msg_Insert_Success); this.OnAfterInsert(new InsertEventArgs() { db = db, data = param.GetData(), executeValue = result }); db.Commit(); return(result); }
/// <summary> /// 获取实体对象 /// </summary> /// <param name="value">主键值</param> /// <returns>返回实体对象T</returns> public T GetEntity(object value) { var columnAttribute = AttributeHelper.GetCustomAttribute <TableAttribute>(typeof(T)); var p = ParamQuery.Instance().From(columnAttribute.TableName).ClearWhere().AndWhere(columnAttribute.PrimaryField, value); return(this.GetEntity(p)); }
/// <summary> /// 分页获取数据列表2。 /// <para>使用公共分页的形式。参数使用分页对象。</para> /// <para>此方法默认使用存储过程(p_com_pagination)的分页方式。(默认查询所有数据。)</para> /// </summary> /// <param name="where">查询条件。如果没有条件可以为null。</param> /// <param name="pageIndex">分页序号,从0开始计数。从哪页开始。</param> /// <param name="pageSize">分页大小。每页显示的记录数。</param> /// <param name="pageCount">输出参数:分页数。</param> /// <param name="total">输出参数:总记录数。</param> /// <returns>返回List数据列表。</returns> public List <T> GetPageList(string where, int pageIndex, int pageSize, out int pageCount, out int total) { pageCount = 0; total = 0; var columnAttribute = AttributeHelper.GetCustomAttribute <TableAttribute>(typeof(T)); if (columnAttribute == null) { throw new Exception("实体对象(" + typeof(T).Name + ")不支持TableAttribute特性"); } return(this.GetPageList(typeof(T).Name, "*", where, columnAttribute.Order, pageIndex, pageSize, out pageCount, out total)); }
/// <summary> /// 获取Insert参数类 /// </summary> /// <param name="data">实体对象</param> /// <returns>ParamInsert</returns> public ParamInsert GetParamInsert(T data) { var paramInsert = ParamInsert.Instance().Insert(typeof(T).Name); var tableAttribute = AttributeHelper.GetCustomAttribute <TableAttribute>(typeof(T)); foreach (PropertyInfo p in typeof(T).GetProperties()) { bool existsC = GetCommonFieldName().ContainsKey(p.Name); // if (p.Name == "tempid" || p.Name == tableAttribute.IdentityField || existsC == true) { continue; } if (tableAttribute.IgnoreInsertFieldsList != null && tableAttribute.IgnoreInsertFieldsList.Contains(p.Name) == true) { continue; } paramInsert.Column(p.Name, data.GetValue(p.Name)); } return(paramInsert); }
/// <summary> /// 分页获取数据列表3。-ClownFish /// <para>使用公共分页的形式。参数使用分页对象。</para> /// <para>此方法默认使用存储过程(p_com_pagination_clownfish)的分页方式。(默认查询所有数据。)</para> /// <para>说明:最后的三个参数一定要是用于分页的参数,且参数名为(前缀部分请自行添加):in PageIndex int, in PageSize int, out TotalRecords int 注意:pageIndex从零开始计数。</para> /// </summary> /// <param name="tableName">表名或者视图名。</param> /// <param name="columns">需要查询的列名,逗号分开。</param> /// <param name="where">查询条件。如果没有条件可以为null。</param> /// <param name="pageIndex">分页序号,从0开始计数。从哪页开始。</param> /// <param name="pageSize">分页大小。每页显示的记录数。</param> /// <param name="pageCount">输出参数:分页数。</param> /// <param name="totalRecords">输出参数:总记录数。</param> /// <returns>返回List数据列表。</returns> public List <T> GetPageList_Fish(string where, int pageIndex, int pageSize, out int pageCount, out int total) { pageCount = 0; total = 0; var attr = AttributeHelper.GetCustomAttribute <TableAttribute>(typeof(T)); PagingInfoExtension parameters = new PagingInfoExtension() { TableName = attr.TableName, Columns = "*", Order = attr.Order, Where = where, PageIndex = pageIndex, PageSize = pageSize, TotalRecords = total }; List <T> list = DbHelper.FillListPaged <T>("p_com_pagination_clownfish", parameters, CommandKind.StoreProcedure);//这个需要提供存储过程名称。 pageCount = parameters.CalcPageCount(); total = parameters.TotalRecords; return(list); }
/// <summary> /// 获取Update参数类 /// </summary> /// <param name="data">实体对象</param> /// <returns>ParamUpdate</returns> public ParamUpdate GetParamUpdate(T data) { var paramUpdate = ParamUpdate.Instance().Update(typeof(T).Name); PropertyInfo[] pis = typeof(T).GetProperties(); var tableAttribute = AttributeHelper.GetCustomAttribute <TableAttribute>(typeof(T)); foreach (PropertyInfo p in pis) { bool existsC = GetCommonFieldName().ContainsKey(p.Name);//排开所有公共字段 if (p.Name == "tempid" || p.Name == tableAttribute.PrimaryField || p.Name == tableAttribute.IdentityField || existsC == true) { continue; } if (tableAttribute.IgnoreUpdateFieldsList != null && tableAttribute.IgnoreUpdateFieldsList.Contains(p.Name) == true) { continue; } paramUpdate.Column(p.Name, data.GetValue(p.Name)); } paramUpdate.AndWhere(tableAttribute.PrimaryField, data.GetValue(tableAttribute.PrimaryField)); return(paramUpdate); }