-
-
Notifications
You must be signed in to change notification settings - Fork 97
Added default constructor for CoreDbContext to allow Code First Migrations #7
Conversation
Thx -- will take a look when I can. |
…e entity to the model (using automapper)
I've added a commit to fix an error I had which is caused by proxy classes for EF. AutoMapper seems to have a problem detecting the correct entity type (it sees the proxy class type) and throws. |
BTW, which connection string should be used with a default ctor? I had the same issues with MembershipReboot. |
I've named the connection string with the default ctor "Thinktecture.IdentityServer.Core", but this can be anything you like. From what I've seen, most libraries tend to use the same name as the project for the connection string. |
BTW, we now have 3 DbContext-derived classes. Any changes to your thinking? |
No, not really. I think it makes things easier, so good refactoring! However, I do wonder whether it is possible to ship the Migration Configuration within the library. Currently, I've created the Configuration classes (now updated to target all three of the contexts), but it should be possible to add this code to the library. Will investigate if possible and what other libraries are doing. |
Regardless whether the Configuration classes should be put in the library, I think it would be best if all the contexts have a default constructor (which implies the use of a default connection string). Could you add those so that we can run code migrations? For example, this is what I am doing now:
and then from the package console Currently, this doesn't work anymore because of the following error: When I pulled the sources, added the ctors myself, everything works wonderfully! :) |
Oh, and if you agree with the changes, could you also push the changes to nuget (or myget)? Would make me very happy 👍 |
The Configuration classes cannot be added to this project; it is not supported. See: https://entityframework.codeplex.com/workitem/2440 You have to add the Configuration classes to your own project, by executing
EF6 will then add the configuration class to your project. Copy and rename it two more times for the other dbcontexts in this project. Furthermore, one should specify MigrationsNamespace for each context in order to distinctly identity which migration belongs to which context
After doing this you can either use automatic-migrations (not recommended) or generate code first migrations classes. As stated in the work item, this will change in EF7. |
Quick update -- I added default ctors to the DbContext classes. I'm now thinking about how to approach migrations. Any updates to your thinking? |
I manually added this on the dev branch. Can you check to see if it allows you to do what you need? |
It's awesome! Thnx 👍 |
#5
After this change, I can succesfully create a code first migration configuration class. From this I can update my database using automatic migrations or, if needed, add code migrations.
You might want to change the default connectionstring. I choose this one, but feel free to change it if you feel like it.