Beispiel #1
0
        internal static bool TryGetEntity <TEntityType>(Type?type, out EntityDefinition <TEntityType>?entityDefinition) where TEntityType : class
        {
            var success = _cachedEntities.TryGetValue(type ?? typeof(TEntityType), out var tempEntity);

            entityDefinition = tempEntity as EntityDefinition <TEntityType>;

            return(success);
        }
Beispiel #2
0
        private static async ValueTask <ulong> CompleteAndWriteRelationValues <TEntity>(NpgsqlConnection connection, NpgsqlBinaryImporter binaryImporter, EntityDefinition <TEntity> entityDefinition, IEnumerable <TEntity> entities, CancellationToken cancellationToken) where TEntity : class
        {
            ulong insertCount = await binaryImporter.CompleteAsync(cancellationToken);

            await binaryImporter.DisposeAsync();

            for (int columnIndex = 0; columnIndex < entityDefinition.ForeignColumnDefinitions.Count; columnIndex++)
            {
                var column = entityDefinition.ForeignColumnDefinitions[columnIndex];

                insertCount += await column.WriteValues(entities, connection, cancellationToken);
            }

            return(insertCount);
        }
Beispiel #3
0
 internal static bool TryAddEntity <TEntityType>(EntityDefinition <TEntityType> entityDefinition, Type?type = null) where TEntityType : class
 {
     return(_cachedEntities.TryAdd(type ?? typeof(TEntityType), entityDefinition));
 }
Beispiel #4
0
        private static async ValueTask <ulong> PerformCopy <TEntity>(NpgsqlConnection connection, EntityDefinition <TEntity> entityDefinition, IEnumerable <TEntity> entities, string command, CancellationToken cancellationToken) where TEntity : class
        {
            var binaryImporter = connection.BeginBinaryImport(command);

            foreach (var entity in entities)
            {
                await binaryImporter.StartRowAsync();

                for (int entityColumnIndex = 0; entityColumnIndex < entityDefinition.ColumnDefinitions.Count; entityColumnIndex++)
                {
                    var entityColumn = entityDefinition.ColumnDefinitions[entityColumnIndex];

                    await entityColumn.WriteValues(entity, binaryImporter, cancellationToken);
                }
            }

            return(await CompleteAndWriteRelationValues(connection, binaryImporter, entityDefinition, entities, cancellationToken));
        }