/// <summary> /// 设置实体 /// </summary> /// <param name="entity">实体</param> private void SetObject(SQLBuilder sqlBuilder, BaseStaff_ExpressEntity entity) { SetObjectExpand(sqlBuilder, entity); sqlBuilder.SetValue(BaseStaff_ExpressEntity.FieldTRANSFER_ADD_FEE, entity.TRANSFER_ADD_FEE); sqlBuilder.SetValue(BaseStaff_ExpressEntity.FieldOWNER_RANGE, entity.OWNER_RANGE); sqlBuilder.SetValue(BaseStaff_ExpressEntity.FieldDISPATCH_ADD_FEE, entity.DISPATCH_ADD_FEE); }
/// <summary> /// 更新实体 /// </summary> /// <param name="entity">实体</param> public int UpdateObject(BaseStaff_ExpressEntity entity) { SQLBuilder sqlBuilder = new SQLBuilder(DbHelper); sqlBuilder.BeginUpdate(this.CurrentTableName); this.SetObject(sqlBuilder, entity); if (UserInfo != null) { sqlBuilder.SetValue(BaseStaff_ExpressEntity.FieldModifiedUserId, UserInfo.Id); sqlBuilder.SetValue(BaseStaff_ExpressEntity.FieldModifiedBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseStaff_ExpressEntity.FieldModifiedOn); sqlBuilder.SetWhere(this.PrimaryKey, entity.ID); return(sqlBuilder.EndUpdate()); }
// 这个是声明扩展方法 partial void SetObjectExpand(SQLBuilder sqlBuilder, BaseStaff_ExpressEntity entity);
/// <summary> /// 添加实体 /// </summary> /// <param name="entity">实体</param> public string AddObject(BaseStaff_ExpressEntity entity) { string key = string.Empty; if (entity.ID != null) { key = entity.ID.ToString(); } SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId); sqlBuilder.BeginInsert(this.CurrentTableName, this.PrimaryKey); if (!this.Identity) { // 这里已经是指定了主键了,所以不需要返回主键了 sqlBuilder.ReturnId = false; sqlBuilder.SetValue(this.PrimaryKey, entity.ID); } else { if (!this.ReturnId && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2)) { if (DbHelper.CurrentDbType == CurrentDbType.Oracle) { sqlBuilder.SetFormula(this.PrimaryKey, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL "); } if (DbHelper.CurrentDbType == CurrentDbType.DB2) { sqlBuilder.SetFormula(this.PrimaryKey, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper()); } } else { if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2)) { BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper); entity.ID = int.Parse(sequenceManager.Increment(this.CurrentTableName)); sqlBuilder.SetValue(this.PrimaryKey, entity.ID); } } } this.SetObject(sqlBuilder, entity); if (UserInfo != null) { sqlBuilder.SetValue(BaseStaff_ExpressEntity.FieldCreateUserId, UserInfo.Id); sqlBuilder.SetValue(BaseStaff_ExpressEntity.FieldCreateBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseStaff_ExpressEntity.FieldCreateOn); if (UserInfo != null) { sqlBuilder.SetValue(BaseStaff_ExpressEntity.FieldModifiedUserId, UserInfo.Id); sqlBuilder.SetValue(BaseStaff_ExpressEntity.FieldModifiedBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseStaff_ExpressEntity.FieldModifiedOn); if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.SqlServer || DbHelper.CurrentDbType == CurrentDbType.Access)) { key = sqlBuilder.EndInsert().ToString(); } else { sqlBuilder.EndInsert(); } if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2)) { return(entity.ID.ToString()); } return(key); }
/// <summary> /// 更新 /// </summary> /// <param name="entity">实体</param> public int Update(BaseStaff_ExpressEntity entity) { return(this.UpdateObject(entity)); }
/// <summary> /// 添加, 这里可以人工干预,提高程序的性能 /// </summary> /// <param name="entity">实体</param> /// <param name="identity">自增量方式,表主键是否采用自增的策略</param> /// <param name="returnId">返回主键,不返回程序允许速度会快,主要是为了主细表批量插入数据优化用的</param> /// <returns>主键</returns> public string Add(BaseStaff_ExpressEntity entity, bool identity = false, bool returnId = false) { this.Identity = identity; this.ReturnId = returnId; return(this.AddObject(entity)); }