-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Suggestion for documentation - Partial classes for your dbContext #3406
Comments
Nice suggestion. I was wondering how to do this and now I see what I was missing. Thanks! |
Glad I could help, I hope the idea helps others as well :) |
Partial classes is one way to do this. Another option is just having static methods that they can call from within Bottom line is that there are lots of ways to organize code and we don't think we need specific docs about how to organize the code in |
What we be really useful would be to make If you are doing DbFirst and recreating the DbContext, it means that any custom OnModelCreating code can be split into a partial class / partial method and the code added to the partial method won't be lost. Currently, after rescaffolding you lose anything custom inside the OnModelCreating override to the underlying DbContext OnModelCreating. |
Something you may want to recommend in the documentation, especially for complex data models, is using a Partial Class for you dbContext class.
By using a pattern such as this, you can keep all the builder logic for your model with your POCO so it is easier to work on in a team environment (low concurrency issue with your MyContext.cs file).
In file Address.cs
And then in your "main" dbContext partial class, you just add the one line of code, Address_CreateObject() in this case for it to call your builder code in the Address.cs file's MyContext partial class.
MyContext.cs
The text was updated successfully, but these errors were encountered: