I am using MVC5 & EF6. I am doing code-first approach. I have some tables that require to be generated using migration (works) and some tables that I need to use from existing database - tables.
in the DbContext class I have
'new table that is created in the DB (works)
public DbSet<Subscription> Subscriptions { get; set; }
public DbSet<Memeber> Members { get; set; }
'existing table.
public DbSet<CodeTable> CodeTable { get; set; }
in the Configuration- (Migration folder)
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
what it does now, it creates a new table called CodeTables
- It becomes plural, why is that?- Can it be turned off?
- How do I use the CodeTable and not generated new table?
- When I delete manually table that was generated using codefirst i.e. Member table. Then I run
Update-Database -Verbose -Force (That doesnt do anything)
Using StartUp project 'Test'.
Using NuGet project 'Test'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'TESTDB' (DataSource: 10.10.50.89, Provider:
System.Data.SqlClient, Origin: Configuration).
No pending explicit migrations.
Running Seed method.
and then run the application, I get an exception
System.Data.SqlClient.SqlException (0x80131904): Invalid object name 'dbo.Members'. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception
because the table not found. Table does not get generated.
How do I let it know that if table not found. Create it?
I noticed if I delete __MigrationHistory and then run the Update-Database. It then complains about my other tables that exists
There is already an object named 'Subscriptions' in the database.
and it only works if I delete all my tables. But this seems to be silly, deleting all tables. I hope there is another approach.