How can we help you today? How can we help you today?

Does SCA support EF Core Code-First Migrations?

We are investigating using SCA to help with migrations in our EF Core 2.1 code-first project. The issue leading us to look at SCA is when deploying migrations to the target database using the CLI the dotnet tool needs access to the source code. E.g. 
dotnet ef database update --project .\Core.DataModel\Core.DataModel.csproj --startup-project Core\Core.csproj
All the examples seem to be for EF6 and if I go through the code-first tutorial at https://documentation.red-gate.com/sca3/tutorials/worked-examples/work-with-entity-framework-codefirst-migrations I get errors when issuing the command below saying the command is unrecognised.
Update-Database -Script -Source $InitialDatabase
marksnelling
0

Comments

3 comments

  • arneh.eskandari
    Hi! This might be because the EF tools are not installed properly. Have you tried any of the suggestions in the following post:
    https://stackoverflow.com/questions/9674983/the-term-update-database-is-not-recognized-as-the-name-of-a-cmdlet 
    arneh.eskandari
    0
  • marksnelling
    Yes that did solve the error I quoted thanks, however the worked example has the command
    Update-Database -Script -Source $InitialDatabase
    That gives the error below.
    <div>Update-Database : A parameter cannot be found that matches parameter name 'Script'.</div><div>At line:1 char:17</div><div>+ Update-Database -Script -Source $InitialDatabase</div><div>+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;~~~~~~~</div><div>&nbsp; &nbsp; + CategoryInfo&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : InvalidArgument: (:) [Update-Database], ParameterBindingExcep&nbsp;</div><div>&nbsp; &nbsp;tion</div><div>&nbsp; &nbsp; + FullyQualifiedErrorId : NamedParameterNotFound,Update-Database</div>
     It seems that the Update-Database command is different between EF6 and EF Core
    marksnelling
    0
  • arneh.eskandari
    You're right. It looks like the new command for generating the migration script in EF Core is Script-Migration
    https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell#script-migration
    I haven't tried this myself but it looks like running Script-Migration -To InitialCreate should achieve the same result
    arneh.eskandari
    0

Add comment

Please sign in to leave a comment.