示例#1
0
        public static async Task BatchCreateAsync <T>(
            this DbSet <T> set, List <T> objs
            ) where T : class
        {
            // TODO: Test
            if (objs.Count < 1)
            {
                return;
            }

            var ctx        = set.GetDbContext();
            var entityType = ctx.Model.FindEntityType(typeof(T));
            var props      = entityType.GetProperties().Select(p => p.PropertyInfo);

            var objBatches = objs.Batches(BatchSize);

            foreach (var objBatch in objBatches)
            {
                var sql = SqlQueryBuilder.BuildCreateQuery(
                    set.GetTableName(), props.ToList(), objBatch.ToList()
                    );
                // TODO: Test
                await ctx.Database.ExecuteSqlRawAsync(sql);
            }
        }
        public void BuildCreateQuery_CorrectParamsPassed_CorrectQueryReturned()
        {
            // Arrange & Act
            var props = typeof(TestObjModel).GetProperties().ToList();
            var sql   = SqlQueryBuilder.BuildCreateQuery(_tableName, props, _objs);

            // Assert
            Assert.AreNotEqual(string.Empty, sql);
        }