예제 #1
0
        /// <summary>
        ///     插入数据
        /// </summary>
        /// <param name="entity">插入数据的实体</param>
        private bool UpdateInner(TData entity)
        {
            if (UpdateByMidified && !entity.__EntityStatus.IsModified)
            {
                return(false);
            }
            int result;

            PrepareSave(entity, DataOperatorType.Update);
            using (var cmd = DataBase.CreateCommand())
            {
                SetUpdateCommand(entity, cmd);
                MySqlDataBase.TraceSql(cmd);
                cmd.CommandText = $@"{BeforeUpdateSql(PrimaryKeyConditionSQL)}
{UpdateSqlCode}
{AfterUpdateSql(PrimaryKeyConditionSQL)}";

                result = cmd.ExecuteNonQuery();
            }

            if (result <= 0)
            {
                return(false);
            }
            EndSaved(entity, DataOperatorType.Update);
            return(true);
        }
예제 #2
0
 /// <summary>
 ///     更新数据
 /// </summary>
 /// <param name="entity">更新数据的实体</param>
 protected bool InsertInner(TData entity)
 {
     PrepareSave(entity, DataOperatorType.Insert);
     using (var cmd = DataBase.CreateCommand())
     {
         var isIdentitySql = SetInsertCommand(entity, cmd);
         MySqlDataBase.TraceSql(cmd);
         if (isIdentitySql)
         {
             var key = cmd.ExecuteScalar();
             if (key == DBNull.Value || key == null)
             {
                 return(false);
             }
             entity.SetValue(KeyField, key);
         }
         else
         {
             if (cmd.ExecuteNonQuery() == 0)
             {
                 return(false);
             }
         }
     }
     EndSaved(entity, DataOperatorType.Insert);
     return(true);
 }
예제 #3
0
        /// <summary>
        ///     更新数据
        /// </summary>
        /// <param name="entity">更新数据的实体</param>
        protected bool InsertInner(TData entity)
        {
            PrepareSave(entity, DataOperatorType.Insert);
            using (var cmd = DataBase.CreateCommand())
            {
                var isIdentitySql = SetInsertCommand(entity, cmd);
                MySqlDataBase.TraceSql(cmd);
                if (isIdentitySql)
                {
                    var key = cmd.ExecuteScalar();
                    if (key == DBNull.Value || key == null)
                    {
                        return(false);
                    }
                    entity.SetValue(KeyField, key);
                }
                else
                {
                    if (cmd.ExecuteNonQuery() == 0)
                    {
                        return(false);
                    }
                }

                var sql = AfterUpdateSql(PrimaryKeyConditionSQL);
                if (!string.IsNullOrEmpty(sql))
                {
                    using (var cmd2 = DataBase.CreateCommand())
                    {
                        cmd2.CommandText = sql;
                        cmd2.Parameters.Add(CreatePimaryKeyParameter(entity.GetValue(KeyField)));
                        cmd2.ExecuteNonQuery();
                    }
                }
            }
            EndSaved(entity, DataOperatorType.Insert);
            return(true);
        }