I created a new .NET project and added ADO.NET EF 6.
I went through the EF wizard and choose Code First from Database.
Then I selected a table. Let's call it "Product".
This created "public partial class Product" and "public partial class Model1".
I immediately created a LINQ query in my application to query the "Product" but I get the following error.
There is already an object named 'Product' in the database.
When I run SQL Profile I see the following:
CREATE TABLE [dbo].[Product] ...
I don't understand why the project is trying to create the table since the table already exists.
I read a couple of articles telling me I need to enable migrations but I really don't want my project to be able to create tables in the database.
(We have a DBA that does not give us access to create tables "easily" in the database)
I then decided to try creating a "Migrations" folder and a "internal sealed class Configuration" with the following:
public Configuration()
{
AutomaticMigrationsEnabled = false;
AutomaticMigrationDataLossAllowed = false;
}
This gives me a new error.
Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.
How to I fix this?
UPDATE
So I created both a VB.NET and a C# application with the exact same code pointing against the same database.
The C# version has the "already in database" issue.
The VB.NET version does not have the "already in database" issue.