Beispiel #1
0
        private void CommitData <TEntity>(InternalDbSet <TEntity> dbSet, TEntity rowInstance, bool forceCommit) where TEntity : class
        {
            if (dbSet == null)
            {
                return;
            }

            if (rowInstance != null)
            {
                _rowList.Add(rowInstance);
            }

            if (_rowList.Count > 0 && (forceCommit || _rowList.Count % 5000 == 0)) //Commit all 500 row
            {
                count += _rowList.Count;
                _logger.LogInformation("Count : " + count);
                List <TEntity> list = new List <TEntity>();
                foreach (TEntity row in _rowList)
                {
                    if (row != null)
                    {
                        list.Add(row);
                    }
                }
                _rowList.Clear();
                if (list.Count > 0)
                {
                    dbSet.AddRange(list);
                    _dbContext.SaveChanges();
                }
            }
        }
            public void Throw_if_collection_is_null()
            {
                var internalContext = new Mock <InternalContext>();
                var internalSet     = new Mock <InternalSetForMock <FakeEntity> >();

                internalSet.Setup(i => i.InternalContext).Returns(internalContext.Object);

                var set = new InternalDbSet <FakeEntity>(internalSet.Object);

                Assert.Equal(
                    new ArgumentNullException("entities").Message,
                    Assert.Throws <ArgumentNullException>(() => set.AddRange(null)).Message);
            }
            public void With_valid_entities_returns_the_added_entities()
            {
                var internalContext = new Mock <InternalContext>();
                var internalSet     = new Mock <InternalSetForMock <FakeEntity> >();

                internalSet.Setup(i => i.InternalContext).Returns(internalContext.Object);

                var set = new InternalDbSet <FakeEntity>(internalSet.Object);

                var entity1 = new FakeEntity();
                var entity2 = new FakeEntity();

                var retVal = (IEnumerable <FakeEntity>)set
                             .AddRange(new[] { entity1, entity2 });

                Assert.True(retVal.Contains(entity1));
                Assert.True(retVal.Contains(entity2));
            }
Beispiel #4
0
 public override void AddRange(IEnumerable <TEntity> entities) => _DbSet.AddRange(entities);