Convert entity structure from database first to first code

I am trying to convert an existing data model from a First database to Code First.

Background

The current solution (in front of me in front of me) uses the database design to determine the model. Then it is published in the database, and then we update the EDMX model from the specified database.

Finally, several T4 templates are executed to create POCO classes from the EDMX model, as well as DBContext .

I want to get rid of this and go exclusively to the First First migration method.

What have i done so far

  • I took the POCO classes created using the T4 template and made them first-class citizens of the project.
  • Then I removed the T4 template from the solution
  • I took the DBC text that was generated by the T4 template and also made it a first-class citizen of the project.
  • Then I removed this T4 template from the solution
  • In the package manager console, I launched "Enable-Migrations" and created the Migrations folder

I also changed the connection string to use the System.Data.SqlClient provider. Was:

 <add name="MyContext" connectionString="metadata=res://Project.Data/Model.MyModel.csdl|res://Project.Data/Model.MyModel.ssdl|res://Project.Data/Model.MyModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=MY-SERVER;initial catalog=MY-DB;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 

Changed to:

 <add name="MyContext" connectionString="data source=MY-SERVER;initial catalog=MY-DB;integrated security=True;multipleactiveresultsets=True;App=EntityFramework" providerName="System.Data.SqlClient" /> 

That's where I have a problem

Now I'm trying to create an initial migration by passing the -IgnoreChanges flag to get an empty migration (given the age of the database, I want future migrations to be based on the current scheme, rather than creating a migration from scratch).

When I run: Add-Migration InitialCreate -IgnoreChanges

I get this error:

Unable to load the specified metadata resource.

When I run: Add-Migration InitialCreate -IgnoreChanges -ConnectionString "data source=MY-SERVER;initial catalog=MY-DB;Integrated Security=SSPI;" -ConnectionStringProviderName "System.Data.SqlClient" Add-Migration InitialCreate -IgnoreChanges -ConnectionString "data source=MY-SERVER;initial catalog=MY-DB;Integrated Security=SSPI;" -ConnectionStringProviderName "System.Data.SqlClient"

I get this error:

It is not possible to redefine the connection for this context with the standard DbConnection because the original connection was EntityConnection.

Into the abyss here. It seems that although I removed the references to the EDMX model, the context still knows about it. I would like to completely get rid of it and go clean Code First.

Any help was appreciated.

+7
c # entity-framework asp.net-mvc-5
source share

No one has answered this question yet.

See related questions:

783
Entity Framework vs LINQ to SQL
758
Entity Framework 5 Record Update
630
The fastest way to embed Entity infrastructure
595
The first code is model / database first
515
How can I get the ID of an inserted object in an Entity framework?
one
edmx link in mvc project
one
Entity Framework Connection String "Server Not Found"
one
Entity Framework Database Connection Does Not Reconnect
0
Error connecting to the first Entity Framework server code
0
Entity Framework Seeding with SqlCeBulkCopy returns an error

All Articles