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

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

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