public async Task <TEntity> InsertAsync <TEntity>(TEntity item, IEnumerable <string> fieldsToInsert = null)
            where TEntity : class
        {
            var query = queryFactory.GetInsertQuery <TEntity>(fieldsToInsert);

            var identityColumn = queryFactory.GetTable <TEntity>().GetIdentityColumn();

            if (identityColumn != null)
            {
                query += "; " + queryFactory.DialectQuery.IdentityQueryFormatSql;
                logger.LogDebug("InsertAsync query:{query} item:{@item}", query, item);
                var fieldId = await Conn.ExecuteScalarAsync(query, item, Tran);

                // Set Property Value
                var propertyColumn = identityColumn.GetPropertyInfo();
                propertyColumn.SetValue(item, Convert.ChangeType(fieldId, propertyColumn.PropertyType));
            }
            else
            {
                logger.LogDebug("InsertAsync query:{query} item:{@item}", query, item);
                await Conn.ExecuteAsync(query, item, Tran);
            }

            return(item);
        }
Ejemplo n.º 2
0
        public async Task <long> GetCountAsync()
        {
            // var sql = $"SELECT count(*) " +
            //   $"FROM {ProcessHistoryDto.TableName} ";

            var tableName = tableQuery.GetTable <ProcessHistoryDto>().Name;
            var sql       = $"SELECT count(*) FROM {tableName}";

            sql = tableQuery.GetCountQuery <ProcessHistoryDto>();

            var count = await DbConnection.ExecuteScalarAsync <long>(sql, DbTransaction);

            return(count);
        }
Ejemplo n.º 3
0
        public bool AddColumn(Type tableType, string columnName)
        {
            if (!tableFactory.IsConfiguredTable(tableType))
            {
                return(false);
            }

            var table = tableFactory.GetTable(tableType);

            if (!tablesConfigured.ContainsKey(table))
            {
                tablesConfigured.Add(table, new HashSet <ColumnConfiguration>());
            }
            var column = table.Columns.FirstOrDefault(c => c.DtoFieldName == columnName);

            if (column != null)
            {
                tablesConfigured[table].Add(column);
                sql.Append(tableFactory.DialectQuery.Encapsulation(column.DbColumnName, table.Identifier));
            }
            return(column != null);
        }
Ejemplo n.º 4
0
        public async Task <TEntity> InsertAsync <TEntity>(TEntity item)
            where TEntity : ITableDto
        {
            var query = queryFactory.GetInsertQuery <TEntity>();

            var identityColumn = queryFactory.GetTable <TEntity>().GetIdentityColumn();

            if (identityColumn != null)
            {
                query += "; " + queryFactory.DialectQuery.IdentityQueryFormatSql;
                var fieldId = await uk.DbConnection.ExecuteScalarAsync(query, item, uk.DbTransaction);

                // Set Property Value
                var propertyColumn = identityColumn.GetPropertyInfo();
                propertyColumn.SetValue(item, Convert.ChangeType(fieldId, propertyColumn.PropertyType));
            }
            else
            {
                await uk.DbConnection.ExecuteAsync(query, item, uk.DbTransaction);
            }

            return(item);
        }