Exemplo n.º 1
0
        private static void StartDemoUseFile()
        {
            System.Console.WriteLine("Starting Demo Application (File)");
            System.Console.WriteLine(string.Empty);

            //var connection = new SQLiteConnection(@"data source=footballDb.sqlite;foreign keys=true", true);

            //var context = new FootballDbContext(connection, false);

            using (var context = new FootballDbContext("footballDb"))
            {
                CreateOrUpdateDatabase(context);
                DisplaySeededData(context);

                var connectionBuilder = new SQLiteConnectionStringBuilder(context.Database.Connection.ConnectionString);
                if (string.IsNullOrEmpty(Path.GetPathRoot(connectionBuilder.DataSource)))
                {
                    connectionBuilder.DataSource = Path.Combine(Directory.GetCurrentDirectory(), connectionBuilder.DataSource);
                }

                System.Console.WriteLine();
                System.Console.WriteLine("After change CodeFirst database structure you need to create a new Migration file with the following command:");
                System.Console.WriteLine("Add-Migration your_change_name -ConnectionString \"{0}\" -ConnectionProviderName \"System.Data.SQLite\"", connectionBuilder);
                System.Console.WriteLine();
                System.Console.WriteLine("But may you need to downgrade Entity Framework to version 6.1.3 to resolve this problem:");
                System.Console.WriteLine("https://stackoverflow.com/questions/47329496/updating-to-ef-6-2-0-from-ef-6-1-3-causes-cannot-access-a-disposed-object-error");
            }
        }
Exemplo n.º 2
0
        private static void StartDemoUseInMemory()
        {
            System.Console.WriteLine("Starting Demo Application (In Memory)");
            System.Console.WriteLine(string.Empty);

            using (var sqLiteConnection = new SQLiteConnection("data source=:memory:"))
            {
                // This is required if a in memory db is used.
                sqLiteConnection.Open();

                using (var context = new FootballDbContext(sqLiteConnection, false))
                {
                    CreateOrUpdateDatabase(context);
                    DisplaySeededData(context);
                }
            }
        }