Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No Migrations? #2

Closed
kacey90 opened this issue Aug 29, 2019 · 5 comments
Closed

No Migrations? #2

kacey90 opened this issue Aug 29, 2019 · 5 comments

Comments

@kacey90
Copy link

kacey90 commented Aug 29, 2019

I find this architecture very nice, especially because of its complexity and the modular approach you adopted. However, I noticed that there are no migrations that creates the DB models from the domain. I have read somewhere that code first migrations bring a lot of issues in enterprise level development especially in production. I feel it's why you probably didn't use it.
I see you have a database project. Does this mean I'll have to create the database and still code the domain models too? Please I need you to throw more light on this.

@kgrzybek
Copy link
Owner

Thank your for that great question @kacey90

In my opinion the best way to manage database changes is using both approaches - versioning state and versioning transitions. I wrote about this 2 articles on my blog:

http://www.kamilgrzybek.com/database/database-change-management/

http://www.kamilgrzybek.com/database/using-database-project-and-dbup-for-database-management/

As you can read from second linked post I use DbUp library and raw migration scripts to create transitions. I don't use EF migrations because I want to have full control on what is applied to my database. I have not added DbUp to this repository yet because it was first release but I definitely have plan to do that :)

@kacey90
Copy link
Author

kacey90 commented Sep 2, 2019

@kgrzybek Thank you for your response. I'll read the articles and try to apply them myself. Many thanks again.

@kacey90 kacey90 closed this as completed Sep 2, 2019
@kacey90
Copy link
Author

kacey90 commented Nov 18, 2019

Sorry that I have to reopen this. I'm trying to use DbUp to handle migrations on the project. But I'm unable to use Migrations to generate the script using "Script-Migration" on Visual Studio or dotnet ef "dotnet ef migrations script" on CLI.
When I tried running the command on the UserAccess.Infrastructure module, It throws the following error;

Unable to create an object of type 'UserAccessContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

I included the -verbose parameter in the command for more details and got this;

System.MissingMethodException: No parameterless constructor defined for type 'IGRMgr.Modules.UserAccess.Infrastructure.UserAccessContext'.

The DbContext seems pretty fine to me. Why wouldn't it work?

@kacey90 kacey90 reopened this Nov 18, 2019
@kgrzybek
Copy link
Owner

kgrzybek commented Nov 20, 2019

In my implementation UserAccessContext does not have parameterless constructor, only this:

public UserAccessContext(DbContextOptions options, ILoggerFactory loggerFactory) : base(options)
{
    _loggerFactory = loggerFactory;
}

So what I understand from the error message, you need to add parameterless constructor to support EF Migrations.

@kacey90
Copy link
Author

kacey90 commented Nov 20, 2019

Yes I noticed. And I tried the parameterless constructor but EF couldn't find the dbContextOptions as a result and threw the following error

No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions object in its constructor and passes it to the base constructor for DbContext.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants