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

Don't locate DbContexts and DbMigrationsConfigurations that cannot be constructed #25

Merged
merged 2 commits into from
Sep 8, 2016

Conversation

nphmuller
Copy link
Contributor

@nphmuller nphmuller commented Sep 8, 2016

When an abstract (or generic) base class is made for either types, they might be used, instead of the implementation.

Example: I have an abstract class DbContextBase and a class MyApplicationContext : DbContextBase.
Migrator.EF6 would incorrectly detect DbContextBase as the single true DbContext, instead of MyApplicationContext.

The constraint I've used are taken from the EF source code

… constructed.

This also solves an issue where and abstract (or generic) base class is made for either types, which is inherited from in an implementation.
Previously the abstract class could be located, instead of the implementation.
@@ -67,7 +67,11 @@ public void EnableMigrations(string outputDir)

private string FindAppDbContextTypeName()
{
var allDbContextTypes = _types.Where(t => typeof(DbContext).IsAssignableFrom(t));
var allDbContextTypes = _types.Where(
t => typeof(DbContext).IsAssignableFrom(t)
Copy link
Owner

@mrahhal mrahhal Sep 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this a method and use it in FindDbMigrationsConfiguration too? (it's duplicated)
Perhaps var allDbContextTypes = GetConstructablesOfType(typeof(DbContext));.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think they did that in the EF source code too. Will add it in a minute.

@mrahhal
Copy link
Owner

mrahhal commented Sep 8, 2016

And @nphmuller, for your info, EF6 is now maintained at GitHub instead of codeplex! Here: aspnet/EntityFramework6.

@nphmuller
Copy link
Contributor Author

nphmuller commented Sep 8, 2016

Thanks for the link!
I moved the duplicate type checking to an extension method. Let me know what you think!

Edit: Ah, I misread your suggestion. If you think a method like GetConstructablesOfType() is better, I'll rewrite it.

@mrahhal
Copy link
Owner

mrahhal commented Sep 8, 2016

Looks great. But I think you used spaces in Executor.cs and in TypeExtensions.cs (I'm using tabs). Please turn them to tabs and I'll merge (ctrl+r ctrl+w will let you see whitespace).
Also, I recommend using this extension for visual studio so that you don't have to switch between spaces/tabs if the project you're contributing to has different set of conventions: editorconfig.

@nphmuller
Copy link
Contributor Author

Should be all tabs now ;)
I'll take a look at the extension. Sounds really handy.

@mrahhal mrahhal merged commit 4c764c4 into mrahhal:master Sep 8, 2016
@mrahhal
Copy link
Owner

mrahhal commented Sep 8, 2016

Thanks a lot!

@nphmuller nphmuller deleted the TypeFindConstraints branch September 8, 2016 12:37
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

Successfully merging this pull request may close these issues.

2 participants