Coming up to speed with Entity Framework Core 2.x
Having used Entity Framework since 4.x, I have seen plenty of examples of what works and what doesn't regarding this library. One of the things that has been a big headache is using the EDMX designer. This is primarily related to using source control. This part of EF will lead to scenarios where code can not be merged easily back into a main branch. Since this was on an existing project, it couldn't be done away with immediately due to time constraints.
Looks like I'm not the only one, judging from the comments on this article.
https://forums.theregister.co.uk/forum/1/2014/10/23/entity_framework_goes_codefirst_only_as_microsoft_shutters_yet_another_visual_modelling_tool/
[ update 4/10/2019 ]
The solution for dealing with the EDMX designer, was to use an extension called "Reverse POCO Generator"
https://marketplace.visualstudio.com/items?itemName=SimonHughes.EntityFrameworkReversePOCOGenerator
This extension lets you have a code-first, EDMX-free approach with an existing database. See the docs at the link for more info. I've been using it well over a year now. However, its unnecessary for EF Core now.
There are plenty of examples out there about using the Dotnet CLI for EF Core, but here is just an example for the command you will need to get familiar with.
dotnet ef dbcontext scaffold "Server=MyDbInstance;Database=MyDbName;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -c MyDbContextName -d -f -o Entities
Notice that this is using a trusted connection, as opposed to your actual application context might use either sql auth or windows auth with the app pool running as a domain account(preferred). The "workflow" will involve using this command after updating your database schema. Contrast this with EF 6.x and the Reverse POCO generator, which will require you to "touch" a TT(T4 Template) file to initiate a rebuild of the db model.
Subscribe to:
Post Comments (Atom)
Add appsettings.json to .NET 6 Console App
When you start a new .NET 6 Console app, you will have little more than what you see here. If one wants to use the json configuration fi...
-
If you only ever deal with one target machine for your app, life is simple. In the "real world" you often have to deal with multi...
-
Work around databases long enough, sooner or later you or your dba will get asked something to the effect "hey, how many sql databases ...
-
Overview With powershell, you can make a request to a url, parse the results and submit a form. Basically, if you can do it in a browser...
No comments:
Post a Comment