static void Main()
        {
            using (var context = new DynamicContext())
            {
                context.Entities.Add(new ConfigurableEntity {
                    IntProperty = 42, StringProperty = "Hello"
                });
                context.SaveChanges();
            }

            using (var context = new DynamicContext {
                IgnoreIntProperty = false
            })
            {
                context.Entities.Add(new ConfigurableEntity {
                    IntProperty = 43, StringProperty = "Hola"
                });
                context.SaveChanges();
            }

            using (var context = new DynamicContext {
                IgnoreIntProperty = true
            })
            {
                context.Entities.Add(new ConfigurableEntity {
                    IntProperty = 44, StringProperty = "Aloha"
                });
                context.SaveChanges();
            }

            using (var context = new DynamicContext())
            {
                var entity = context.Entities.Single();

                Console.WriteLine($"{entity.IntProperty} {entity.StringProperty}");
            }

            using (var context = new DynamicContext {
                IgnoreIntProperty = false
            })
            {
                var entity = context.Entities.Single();

                Console.WriteLine($"{entity.IntProperty} {entity.StringProperty}");
            }

            using (var context = new DynamicContext {
                IgnoreIntProperty = true
            })
            {
                var entity = context.Entities.Single();

                Console.WriteLine($"{entity.IntProperty} {entity.StringProperty}");
            }
        }
Example #2
0
        private static void Main()
        {
            // Note that because this sample uses InMemory as its provider, each model gets it's own separate store.

            using (var context = new DynamicContext {
                UseIntProperty = true
            })
            {
                context.Entities.Add(new ConfigurableEntity {
                    IntProperty = 44, StringProperty = "Aloha"
                });
                context.SaveChanges();
            }

            using (var context = new DynamicContext {
                UseIntProperty = false
            })
            {
                context.Entities.Add(new ConfigurableEntity {
                    IntProperty = 43, StringProperty = "Hola"
                });
                context.SaveChanges();
            }

            using (var context = new DynamicContext {
                UseIntProperty = true
            })
            {
                var entity = context.Entities.Single();

                // Writes 44 and an empty string
                Console.WriteLine($"{entity.IntProperty} {entity.StringProperty}");
            }

            using (var context = new DynamicContext {
                UseIntProperty = false
            })
            {
                var entity = context.Entities.Single();

                // Writes 0 and an "Hola"
                Console.WriteLine($"{entity.IntProperty} {entity.StringProperty}");
            }
        }