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="data source=MY-SERVER;initial catalog=MY-DB;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" 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.
c # entity-framework asp.net-mvc-5
Brendan green
source share