private static void Main()
        {
            var context = new PersistingAndConstructingEntitiesContext();

            CreateDatabase(context);

            Console.Clear();

            DisplayDemoStep("Creating entities");

            var newEntityWithRichProperties = new EntityWithRichProperties();

            newEntityWithRichProperties.SomePropertyWithRichLogic      = 123456789;
            newEntityWithRichProperties.SomeOtherPropertyWithRichLogic = -987654321;

            var entityWithoutProperties = new EntityWithoutProperties();

            entityWithoutProperties.SetValues(123456789, -987654321);

            DisplayDemoStep("Adding the entities to the database");

            context.EntitiesWithRichProperties.Add(newEntityWithRichProperties);
            context.EntitiesWithoutProperties.Add(entityWithoutProperties);
            context.SaveChanges();

            DisplayDemoStep("Loading the entities from the database");

            context = new PersistingAndConstructingEntitiesContext();

            var loadedEntityWithRichProperties = context.EntitiesWithRichProperties.First();
            var loadedEntityWithoutProperties  = context.EntitiesWithoutProperties.First();

            DisplayDemoStep("Displaying the loaded entities");

            DisplayText($"Loaded entity with rich properties:{Environment.NewLine}" +
                        $"{nameof(EntityWithRichProperties.Id)} = {loadedEntityWithRichProperties.Id}{Environment.NewLine}" +
                        $"{nameof(EntityWithRichProperties.SomePropertyWithRichLogic)} = {loadedEntityWithRichProperties.SomePropertyWithRichLogic}{Environment.NewLine}" +
                        $"{nameof(EntityWithRichProperties.SomeOtherPropertyWithRichLogic)} = {loadedEntityWithRichProperties.SomeOtherPropertyWithRichLogic}{Environment.NewLine}");

            DisplayText($"Loaded entity without properties:{Environment.NewLine}" +
                        $"{nameof(EntityWithoutProperties.GetId)} = {loadedEntityWithoutProperties.GetId()}{Environment.NewLine}" +
                        $"{nameof(EntityWithoutProperties.GetSomeValue)} = {loadedEntityWithoutProperties.GetSomeValue()}{Environment.NewLine}" +
                        $"{nameof(EntityWithoutProperties.GetSomeOtherValue)} = {loadedEntityWithoutProperties.GetSomeOtherValue()}{Environment.NewLine}");
        }
Exemplo n.º 2
0
        private static void Main()
        {
            var context = new PersistingAndConstructingEntitiesContext();

            CreateDatabase(context);

            Console.Clear();

            DisplayDemoStep("Creating entities");

            var newEntityWithConstructorAndProperties = new EntityWithConstructorAndProperties(123456789, "-987654321");

            var newEntityWithConstructorAndFields = new EntityWithConstructorAndFields(123456789, "-987654321");

            DisplayDemoStep("Adding the entities to the database");

            context.EntitiesWithConstructorAndProperties.Add(newEntityWithConstructorAndProperties);
            context.EntitiesWithConstructorAndFields.Add(newEntityWithConstructorAndFields);
            context.SaveChanges();

            DisplayDemoStep("Loading the entities from the database");

            context = new PersistingAndConstructingEntitiesContext();

            var loadedEntityWithConstructorAndProperties = context.EntitiesWithConstructorAndProperties.First();
            var loadedEntityWithConstructorAndFields     = context.EntitiesWithConstructorAndFields.First();

            DisplayDemoStep("Displaying the loaded entities");

            DisplayText($"Loaded entity with constructor and properties:{Environment.NewLine}" +
                        $"{nameof(EntityWithConstructorAndProperties.Id)} = {loadedEntityWithConstructorAndProperties.Id}{Environment.NewLine}" +
                        $"{nameof(EntityWithConstructorAndProperties.SomeProperty)} = {loadedEntityWithConstructorAndProperties.SomeProperty}{Environment.NewLine}" +
                        $"{nameof(EntityWithConstructorAndProperties.SomeOtherProperty)} = {loadedEntityWithConstructorAndProperties.SomeOtherProperty}{Environment.NewLine}");

            DisplayText($"Loaded entity constructor and fields:{Environment.NewLine}" +
                        $"{nameof(EntityWithConstructorAndFields.Id)} = {loadedEntityWithConstructorAndFields.Id}{Environment.NewLine}" +
                        $"{nameof(EntityWithConstructorAndFields.GetSomeValue)} = {loadedEntityWithConstructorAndFields.GetSomeValue()}{Environment.NewLine}" +
                        $"{nameof(EntityWithConstructorAndFields.GetSomeOtherValue)} = {loadedEntityWithConstructorAndFields.GetSomeOtherValue()}{Environment.NewLine}");
        }