예제 #1
0
        /// <summary>
        /// Executes <see cref="UpdateStatement{TEntity}"/> and updates cached objects
        /// </summary>
        /// <param name="stmt"></param>
        /// <typeparam name="TEntity"></typeparam>
        public void Update <TEntity>(UpdateStatement <TEntity> stmt)
        {
            var conn = _connection;

            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            using var cmd   = conn.CreateCommand();
            cmd.CommandText = stmt.AsSqlString();
            cmd.Transaction = _transaction;
            foreach (var(type, id, value) in stmt.GetParameters())
            {
                var param = cmd.CreateParameter();
                param.Value         = value;
                param.DbType        = type;
                param.ParameterName = id;
                cmd.Parameters.Add(param);
            }

            using var reader = new CachedDataReader(
                      _ctx.Cache,
                      stmt.Entity,
                      cmd.ExecuteReader(),
                      _ctx
                      );
            // consume update query to execute reader
            foreach (var _ in reader.ReadAll().ToList())
            {
            }
        }
예제 #2
0
 public void TestSimpleStatement()
 {
     var updateStatement = new UpdateStatement(
         TestEntity,
         new List<IWhereFilter>(),
         new List<UpdateColumnStatement>() {
             UpdateStatements[0]
         }
     );
     Assert.AreEqual("UPDATE table_name t1 SET column1 = @a;", updateStatement.AsSqlString());
 }
예제 #3
0
 public void TestWithMultipleUpdate()
 {
     var updateStatement = new UpdateStatement(
         TestEntity,
         new List<IWhereFilter>() { WhereFilters[0] },
         UpdateStatements
     );
     Assert.AreEqual("UPDATE table_name t1 SET column1 = @a, column2 = @b WHERE t1.column2 = @test2;", updateStatement.AsSqlString());
 }
예제 #4
0
 public void TestWithWhere()
 {
     var updateStatement = new UpdateStatement(
         TestEntity,
         new List<IWhereFilter>() { WhereFilters[0] },
         new List<UpdateColumnStatement>() { UpdateStatements[1] }
     );
     Assert.AreEqual("UPDATE table_name t1 SET column2 = @b WHERE t1.column2 = @test2;", updateStatement.AsSqlString());
 }