Best Practice MS SQL

From MgmtWiki
Revision as of 15:22, 27 July 2020 by Tom (talk | contribs) (Issues)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Full Title

Best Practices and Issues with Microsoft SQL Server


Unable to create an object of type 'ServiceDbContext'. For the different patterns supported at design time

You get that error because to generate migrations you need either:

  1. A DbContext with a default constructor (that is, a parameterless constructor)
  2. Being able to get the DbContext from ApplicationServices (that is, Dependency Injection)
  3. A design time factory that returns a properly configured DbContext.

Since ApplicationDbContext constructor has a parameter, you have to use options 2 or 3. See the details in the article:

But option 2 (the one originally used) doesn't work any more, because the program startup was changed to improve logging.

And, since there's no DesignTimeFactory for ApplicationDbContext you just won't be able to create migrations at this time.

If you want to learn about this way for creating migrations you can:

Create an ApplicationDbContextDesignTimeFactory, similar to CatalogContextDesignFactory or IntegrationEventLogContextDesignTimeFactory, or Try with other microservice like Catalog.API, that already has its DesignTimeFactory.