Exemple #1
0
        public void TestInsertCommandWithReturnAffectedId()
        {
            var insertingRow = _table.Rows.FirstOrDefault();
            var query        = _crudCommandDirector.BuildInsertCommand(_table, insertingRow);

            Assert.Equal("INSERT INTO data.Car(gid, Brand, Cost) VALUES('0', 'Audi', '1000') RETURNING gid", query);
        }
        public async Task <int> InsertData(int tableId, Row insertingRow)
        {
            var tableMeta = await _dbContext.TableInfos.Where(x => x.Id == tableId)
                            .Include(x => x.FieldInfos).FirstAsync();

            if (tableMeta == null)
            {
                throw new TableNotFoundException(tableId);
            }

            var table = _mapper.Map <Table>(tableMeta);

            var insertQuery = _commandDirector.BuildInsertCommand(table, insertingRow);

            var insertedRowId = _dbContext.ExecuteSqlQuery(insertQuery);

            return(insertedRowId);
        }