Exemple #1
0
 protected virtual void UpdateItem(Type type, object entity, bool byView, DbConnection conn)
 {
     using (var transaction = conn.BeginTransaction(IsolationLevel.ReadCommitted))
     {
         var cmd = conn.CreateCommand();
         cmd.Transaction = transaction;
         try
         {
             var avoidFields        = GetAvoidFields(type, byView);
             var updateQueryBuilder = new UpdateQueryBuilder(entity, type, avoidFields, _mapping, GeometryQuery,
                                                             byView);
             string sql = updateQueryBuilder.ToString();
             var    parametersBuilder = new ParametersBuilder(entity, cmd, updateQueryBuilder.Fields);
             cmd.Parameters.AddRange(parametersBuilder.Parameters.ToArray());
             cmd.CommandText = sql;
             cmd.ExecuteNonQuery();
             transaction.Commit();
         }
         catch (Exception ex)
         {
             transaction.Rollback();
             throw ex;
         }
     }
 }
Exemple #2
0
 protected void DeleteItem(DBEntity entity, bool byView, DbConnection conn)
 {
     using (var transaction = conn.BeginTransaction())
     {
         try
         {
             var cmd = conn.CreateCommand();
             cmd.Transaction = transaction;
             var type = entity.GetType();
             var deleteQueryBuilder = new DeleteQueryBuilder(entity, type, _mapping, byView);
             cmd.CommandText = deleteQueryBuilder.ToString();
             var parametersBuilder = new ParametersBuilder(entity, cmd, deleteQueryBuilder.Fields);
             cmd.Parameters.AddRange(parametersBuilder.Parameters.ToArray());
             cmd.ExecuteNonQuery();
             transaction.Commit();
         }
         catch (Exception)
         {
             transaction.Rollback();
             throw;
         }
     }
 }
Exemple #3
0
        protected virtual void InsertItem(Type type, object entity, bool byView, DbConnection conn)
        {
            using (var transaction = conn.BeginTransaction(IsolationLevel.ReadCommitted))
            {
                var insertCmd = conn.CreateCommand();
                insertCmd.Transaction = transaction;
                try
                {
                    var avoidFields        = GetAvoidFields(type, byView);
                    var insertQuerybuilder = new InsertQueryBuilder(entity, type,
                                                                    avoidFields.Concat(new string[] { GeometryQuery.GeometryField }), _mapping,
                                                                    GeometryQuery, byView);


                    //var insertCmd = conn.CreateCommand();
                    if (type.GetType().Name.Contains("Connectivity_n"))
                    {
                        CYZLog.writeLog(insertQuerybuilder.ToString());
                    }


                    insertCmd.CommandText = insertQuerybuilder.ToString();
                    ParametersBuilder tempParameterBulider = new ParametersBuilder(entity, insertCmd, insertQuerybuilder.Fields);

                    insertCmd.Parameters.AddRange(tempParameterBulider.Parameters.ToArray());

                    insertCmd.ExecuteNonQuery();
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    LogManager.Instance.Error(ex);
                    transaction.Rollback();
                    throw ex;
                }
            }
        }