Beispiel #1
0
        // Must be called from inside the lock
        private IInMemoryTable EnsureTable(object key, IEntityType entityType)
        {
            if (_tables == null)
            {
                _tables = CreateTables();
            }

            if (!_tables.TryGetValue(key, out var table))
            {
                _tables.Add(key, table = _tableFactory.Create(entityType));
            }

            return(table);
        }
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        public virtual int ExecuteTransaction(
            IEnumerable <IUpdateEntry> entries,
            IInterceptingLogger <LoggerCategory.Update> updateLogger)
        {
            var rowsAffected = 0;

            lock (_lock)
            {
                foreach (var entry in entries)
                {
                    var entityType = entry.EntityType;

                    Debug.Assert(!entityType.IsAbstract());

                    IInMemoryTable table;
                    if (!_tables.Value.TryGetValue(entityType, out table))
                    {
                        _tables.Value.Add(entityType, table = _tableFactory.Create(entityType));
                    }

                    switch (entry.EntityState)
                    {
                    case EntityState.Added:
                        table.Create(entry);
                        break;

                    case EntityState.Deleted:
                        table.Delete(entry);
                        break;

                    case EntityState.Modified:
                        table.Update(entry);
                        break;
                    }

                    rowsAffected++;
                }
            }

            updateLogger.LogInformation <object>(
                InMemoryEventId.SavedChanges,
                rowsAffected,
                InMemoryStrings.LogSavedChanges);

            return(rowsAffected);
        }
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        public virtual int ExecuteTransaction(
            IEnumerable <IUpdateEntry> entries,
            IDiagnosticsLogger <DbLoggerCategory.Update> updateLogger)
        {
            var rowsAffected = 0;

            lock (_lock)
            {
                foreach (var entry in entries)
                {
                    var entityType = entry.EntityType;

                    Debug.Assert(!entityType.IsAbstract());

                    var key = _useNameMatching ? (object)entityType.Name : entityType;
                    if (!_tables.Value.TryGetValue(key, out var table))
                    {
                        _tables.Value.Add(key, table = _tableFactory.Create(entityType));
                    }

                    switch (entry.EntityState)
                    {
                    case EntityState.Added:
                        table.Create(entry);
                        break;

                    case EntityState.Deleted:
                        table.Delete(entry);
                        break;

                    case EntityState.Modified:
                        table.Update(entry);
                        break;
                    }

                    rowsAffected++;
                }
            }

            updateLogger.ChangesSaved(entries, rowsAffected);

            return(rowsAffected);
        }
Beispiel #4
0
        // Must be called from inside the lock
        private IInMemoryTable EnsureTable(IEntityType entityType)
        {
            if (_tables == null)
            {
                _tables = CreateTables();
            }

            IInMemoryTable baseTable = null;

            var entityTypes = entityType.GetAllBaseTypesInclusive();

            foreach (var currentEntityType in entityTypes)
            {
                var key = _useNameMatching ? (object)currentEntityType.FullName() : currentEntityType;
                if (!_tables.TryGetValue(key, out var table))
                {
                    _tables.Add(key, table = _tableFactory.Create(currentEntityType, baseTable));
                }

                baseTable = table;
            }

            return(_tables[_useNameMatching ? (object)entityType.FullName() : entityType]);
        }