Exemple #1
0
        /// <summary>
        /// 保存实体数据(新增、修改)
        /// <param name="keyValue">主键</param>
        /// <param name="entity">实体</param>
        /// <summary>
        /// <returns></returns>
        public void SaveEntity(string keyValue, LGTypeEntity entity)
        {
            var db = this.BaseRepository().BeginTrans();

            try
            {
                if (!string.IsNullOrEmpty(keyValue))
                {
                    //更改映照表对应字段
                    var oldentity = GetEntity(keyValue);
                    var sql       = "UPDATE LR_Lg_Map SET F_TypeCode='" + entity.F_Code + "' WHERE F_TypeCode='" + oldentity.F_Code + "'";
                    db.ExecuteBySql(sql);
                    entity.Modify(keyValue);
                    db.Update(entity);
                }
                else
                {
                    entity.Create();
                    db.Insert(entity);
                }
                db.Commit();
            }
            catch (Exception ex)
            {
                db.Rollback();
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }