8

Debugging Entity Framework Seed methods

 3 years ago
source link: https://stevedrivendevelopment.com/2014/12/10/debugging-entity-framework-seed-methods/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Debugging Entity Framework Seed methods

In Entity Framework projects, sometimes you need to debug your seed methods. This can seem a little tricky, since the code tends to run in the Package Manager Console;

pmc

And it’s a fire-and-forget kind of deal. Any runtime errors get swallowed. However, you can debug into your own EF code by;

1) Find the project that contains your DbContext and Configuration.cs file, and set it as your startup project.

2) Open the properties page for the project.

3) Set the external program to the EF migator exe. For EF 6.1, it’s at

($mySourceDirectory)\packages\EntityFramework.6.1.0\tools\migrate.exe

4) Set the command line arguments to point to the name of your EF assembly, the bin folder for that EF assembly, and the web.config or app.config which contains the connection string for the DB you’ll be updating, like so;

MyProject.EntityFramework.dll /startupConfigurationFile="..\..\..\MyWebsite\Web.config" /startupDirectory="full\path\to\MyProjectEntityFramework\bin\Debug"

5) Set breakpoints and press F5!

Post navigation

2 thoughts on “Debugging Entity Framework Seed methods”

  1. f6c2a9a896ed51f8fa802b69caac87e9?s=40&d=identicon&r=Gapachetechuk says:

    I’ve got as far as Step #2.

    In Step #3: What do you mean by “Set the external program to the EF migator exe”? Where?How? What?

    In Step #4: You say “Set the command line arguments”. Is that re-build, or post-build?

    In Step #5: Will this give proper feedback in the Package Manager Console whein I run “Update-Database -Verbose”?

    • 2b31f1c54790d6cba8a63a3653a26c49?s=40&d=identicon&r=GSteve Cooper says:

      Hi – right-click the project, choose properties, and go to the debugging tab. That has boxes for the external program and runtime arguments, so that deals with step 3 and 4.

      As to running the powershell command; that powershell command just invokes migrate.exe, the app you set in step 3, so could probably get verbose output with a command-line switch, which you would add to the arguments listed for Step 4. Eg, it will be something like /verbose, added to the end of the args. When you debug it should write the scripts to the console window that appears.

      I can’t check the args right now because I’m in my phone but you can get them by running migrate.exe /?.

      (https://msdn.microsoft.com/en-gb/data/jj618307.aspx)

      Hope that helps!

Leave a Reply Cancel reply


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK