/// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="entity">实体</param>
 private void SetObject(SQLBuilder sqlBuilder, UserByGUIDEntity entity)
 {
     SetObjectExpand(sqlBuilder, entity);
     sqlBuilder.SetValue(UserByGUIDEntity.FieldFullName, entity.FullName);
     sqlBuilder.SetValue(UserByGUIDEntity.FieldSalary, entity.Salary);
     sqlBuilder.SetValue(UserByGUIDEntity.FieldAge, entity.Age);
     sqlBuilder.SetValue(UserByGUIDEntity.FieldBirthday, entity.Birthday);
     sqlBuilder.SetValue(UserByGUIDEntity.FieldPhoto, entity.Photo);
     sqlBuilder.SetValue(UserByGUIDEntity.FieldAllowEdit, entity.AllowEdit);
     sqlBuilder.SetValue(UserByGUIDEntity.FieldAllowDelete, entity.AllowDelete);
     sqlBuilder.SetValue(UserByGUIDEntity.FieldEnabled, entity.Enabled);
     sqlBuilder.SetValue(UserByGUIDEntity.FieldDeletionStateCode, entity.DeletionStateCode);
     sqlBuilder.SetValue(UserByGUIDEntity.FieldSortCode, entity.SortCode);
     sqlBuilder.SetValue(UserByGUIDEntity.FieldDescription, entity.Description);
 }
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体</param>
        public int UpdateObject(UserByGUIDEntity entity)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);

            sqlBuilder.BeginUpdate(this.CurrentTableName);
            this.SetObject(sqlBuilder, entity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(UserByGUIDEntity.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(UserByGUIDEntity.FieldModifiedBy, UserInfo.Realname);
            }
            sqlBuilder.SetDBNow(UserByGUIDEntity.FieldModifiedOn);
            sqlBuilder.SetWhere(this.PrimaryKey, entity.UserId);
            return(sqlBuilder.EndUpdate());
        }
 // 这个是声明扩展方法
 partial void SetObjectExpand(SQLBuilder sqlBuilder, UserByGUIDEntity entity);
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity">实体</param>
        public string AddObject(UserByGUIDEntity entity)
        {
            string sequence = string.Empty;

            if (entity.SortCode == null || entity.SortCode == 0)
            {
                BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
                sequence        = sequenceManager.Increment(this.CurrentTableName);
                entity.SortCode = int.Parse(sequence);
            }
            if (entity.UserId != null)
            {
                sequence = entity.UserId.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.UserId);
            }
            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))
                    {
                        sqlBuilder.SetValue(this.PrimaryKey, entity.UserId);
                    }
                }
            }
            this.SetObject(sqlBuilder, entity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(UserByGUIDEntity.FieldCreateUserId, UserInfo.Id);
                sqlBuilder.SetValue(UserByGUIDEntity.FieldCreateBy, UserInfo.Realname);
            }
            sqlBuilder.SetDBNow(UserByGUIDEntity.FieldCreateOn);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(UserByGUIDEntity.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(UserByGUIDEntity.FieldModifiedBy, UserInfo.Realname);
            }
            sqlBuilder.SetDBNow(UserByGUIDEntity.FieldModifiedOn);
            if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.SqlServer || DbHelper.CurrentDbType == CurrentDbType.Access))
            {
                sequence = sqlBuilder.EndInsert().ToString();
            }
            else
            {
                sqlBuilder.EndInsert();
            }
            return(sequence);
        }
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="entity">实体</param>
 public int Update(UserByGUIDEntity entity)
 {
     return(this.UpdateObject(entity));
 }
 /// <summary>
 /// 添加, 这里可以人工干预,提高程序的性能
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="identity">自增量方式,表主键是否采用自增的策略</param>
 /// <param name="returnId">返回主键,不返回程序允许速度会快,主要是为了主细表批量插入数据优化用的</param>
 /// <returns>主键</returns>
 public string Add(UserByGUIDEntity entity, bool identity = false, bool returnId = false)
 {
     this.Identity = identity;
     this.ReturnId = returnId;
     return(this.AddObject(entity));
 }