Exemple #1
0
        public async Task BulkInsertDefaultValuesForPropertiesAsync()
        {
            var prov = GetServiceProvider();
            var ctx  = prov.GetService <TestContext>();

            var items = Enumerable.Range(1, 100)
                        .Select(p =>
            {
                var result = new SimpleTableWithShadowProperty
                {
                    Title = $"Title {p}"
                };
                if (p % 2 == 0)
                {
                    result.StoreValue("Description_de", $"Description Value {0}");
                    result.ModificationDate = DateTime.Now;
                }
                return(result);
            })
                        .ToList();

            await ctx.BulkInsertAsync(items, p => p.ShadowPropertyAccessor(ShadowPropertyAccessor.Current));

            var defaultItems = await ctx.SimpleTableWithShadowProperty.Where(p => EF.Property <string>(p, "Description_de") == "Default").ToListAsync();

            var otherItems = await ctx.SimpleTableWithShadowProperty.Where(p => EF.Property <string>(p, "Description_de") != "Default").ToListAsync();

            Assert.AreEqual(50, defaultItems.Count);
            Assert.AreEqual(50, otherItems.Count);

            otherItems.ForEach(p => ((string)ctx.Entry(p).Property("Description_de").CurrentValue).StartsWith("Description Value "));
            defaultItems.ForEach(p => Assert.AreEqual(p.ModificationDate, DateTime.MinValue));
            otherItems.ForEach(p => Assert.True(p.ModificationDate > DateTime.Now.AddHours(-1)));
        }
Exemple #2
0
        public async Task BulkInsertShadowPropertyEntityIncludeShadowPropertyAsync()
        {
            var prov = GetServiceProvider();
            var ctx  = prov.GetService <TestContext>();

            var items = Enumerable.Range(1, 100)
                        .Select(p =>
            {
                var result = new SimpleTableWithShadowProperty
                {
                    Title = $"Title {p}"
                };
                result.StoreValue("Description_de", $"Description Value {0}");
                return(result);
            })
                        .ToList();

            await ctx.BulkInsertAsync(items, p => p.ShadowPropertyAccessor(ShadowPropertyAccessor.Current));

            var allItems = await ctx.SimpleTableWithShadowProperty.ToListAsync();

            allItems.ForEach(p => ((string)ctx.Entry(p).Property("Description_de").CurrentValue).StartsWith("Description Value "));
        }
Exemple #3
0
        public async Task BulkInsertShadowPropertyEntityIgnoreShadowPropertyAsync()
        {
            var prov = GetServiceProvider();
            var ctx  = prov.GetService <TestContext>();

            var items = Enumerable.Range(1, 100)
                        .Select(p =>
            {
                var result = new SimpleTableWithShadowProperty
                {
                    Title = $"Title {p}"
                };
                result.StoreValue("Description_de", $"Description Value {0}");
                return(result);
            })
                        .ToList();

            await ctx.BulkInsertAsync(items);

            var allItems = await ctx.SimpleTableWithShadowProperty.ToListAsync();

            allItems.ForEach(p => Assert.AreEqual("DEFAULT", ctx.Entry(p).Property("Description_de").CurrentValue));
        }