Exemplo n.º 1
0
        public static IWriteCommand CreateCommand(EntityEntry entityEntry)
        {
            var entityType = entityEntry.EntityType;
            var method     = GenericsHelper.GetMethodDelegate <Func <EntityEntry, IWriteCommand> >(
                typeof(EntityCommandBuilder), nameof(InternalCreateCommand), entityType
                );

            return(method(entityEntry));
        }
        public string GenericHelper()
        {
            var method = GenericsHelper.GetMethodDelegate <Func <Type, string, string> >(
                typeof(GenericMethodInvokeBenchmark),
                nameof(MyGenericMethod),
                typeof(int)
                );

            return(method(typeof(int), "1"));
        }
        public virtual void SaveChanges()
        {
            ChangeTracker.DetectChanges();
            AfterDetectChanges();
            var commands          = GenerateWriteCommands();
            var writeModelOptions = GetWriteModelOptions();

            var commandsByEntityType = commands.GroupBy(c => c.EntityType);

            foreach (var entityTypeCommands in commandsByEntityType)
            {
                var method = GenericsHelper.GetMethodDelegate <Action <IMongoDbConnection, IEnumerable <IWriteCommand>, WriteModelOptions> >(
                    typeof(MongoDbContext), nameof(InternalSaveChanges), entityTypeCommands.Key
                    );
                method(Connection, entityTypeCommands, writeModelOptions);
            }

            ChangeTracker.CommitChanges();
            CommandStaging.CommitChanges();
        }
        public virtual async Task SaveChangesAsync(CancellationToken cancellationToken = default)
        {
            ChangeTracker.DetectChanges();
            AfterDetectChanges();
            var commands          = GenerateWriteCommands();
            var writeModelOptions = GetWriteModelOptions();

            var commandsByEntityType = commands.GroupBy(c => c.EntityType);

            foreach (var entityTypeCommands in commandsByEntityType)
            {
                var methodAsync = GenericsHelper.GetMethodDelegate <Func <IMongoDbConnection, IEnumerable <IWriteCommand>, WriteModelOptions, CancellationToken, Task> >(
                    typeof(MongoDbContext), nameof(InternalSaveChangesAsync), entityTypeCommands.Key
                    );
                await methodAsync(Connection, entityTypeCommands, writeModelOptions, cancellationToken);
            }

            ChangeTracker.CommitChanges();
            CommandStaging.CommitChanges();
        }