Exemple #1
0
        private static void RemoveTwoEntitiesWithFilteredIndex(JustDatabaseContext context)
        {
            Console.WriteLine("Deleting entities...");
            var entitiesToDelete = context.Users.Where(x => x.IsActive == false);

            context.RemoveRange(entitiesToDelete);

            SaveChangesAndWriteToConsoleException(context);
        }
Exemple #2
0
 private static void CreateTwoTheSameEntitiesWhichDoNotMetFilterConditions(JustDatabaseContext context)
 {
     context.Users.Add(new Model.User {
         IsActive = false, Login = "******", Email = "*****@*****.**"
     });
     context.Users.Add(new Model.User {
         IsActive = false, Login = "******", Email = "*****@*****.**"
     });
     context.SaveChanges();
 }
Exemple #3
0
        static void Main(string[] args)
        {
            InitializeDiContainer();
            JustDatabaseContext context = MigrateDatabase();

            CreateTwoTheSameEntitiesWhichDoNotMetFilterConditions(context);
            UpdateTwoEntitiesWithFilteredIndex(context);
            RemoveTwoEntitiesWithFilteredIndex(context);
            // CleanupDatabase(context);
            Console.ReadKey();
        }
Exemple #4
0
        private static void UpdateTwoEntitiesWithFilteredIndex(JustDatabaseContext context)
        {
            Console.WriteLine("Updating entities...");
            var entitiesToUpdate = context.Users.Where(x => x.IsActive == false);
            int i = 0;

            foreach (var entity in entitiesToUpdate)
            {
                entity.Login = "******" + i++;
            }

            SaveChangesAndWriteToConsoleException(context);
        }
Exemple #5
0
 private static void SaveChangesAndWriteToConsoleException(JustDatabaseContext context)
 {
     try
     {
         // The problem occurs during saving changes
         context.SaveChanges();
     }
     catch (Exception ex)
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine(ex.Message);
         Console.ResetColor();
     }
 }
Exemple #6
0
 private static void CleanupDatabase(JustDatabaseContext context)
 {
     context.RemoveRange(context.Users);
     context.SaveChanges();
 }