-
Notifications
You must be signed in to change notification settings - Fork 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
database EnsureDeleted & EnsureCreated #4028
Comments
@DickBaker the drop+create in the samples on that page are already placed in an xunit class fixture, which means that these operations execute once, before the tests are executed. However, database drop and create still are relatively heavy operations, and when quickly iterating over code changes and re-running tests over and over, it may be worth temporarily commenting those lines out. Hope that makes sense. |
@roji, yes the fixture means 1-off, but propose guideline to devs to employ static ctor anyway in their own code. I agree heavy impact, but EnsureCreated should be quick if db does exist (and if it doesn't it is obviously worth its o/h). |
What's the advantage of using a static constructor rather than the class fixture? The point of doing it in a class fixture is that the same fixture type can be used multiple times to manage different databases; this isn't possible with a static constructor, which runs only once.
In any normal development process, the database always already exists from the last time you ran the tests.
The WHERE clause is required on SQL Server (which is what the sample is for). |
Note from triage: this is not something we plan to do. |
The "DELETE FROM [Blogs] WHERE 1=1;" clause is required on SQL Server (which is what the sample is for) |
@DickBaker just try it out on SQL Server. Doing |
weird! Trying to repro your experience I have just tried my SSMS apps I am aware that SSMS has a Tools, Options, Designers, Table and Database Designers : "Prevent saving changes that require table re-creation" to prevent meltdowns, but I could find no other config settings server/client-side to explain your UX Please run the @@Version, sp_configure stuff, SSMS/ADS options and any QP (& qry opts) so we can see what is causing that. Roji, I have to admit shock that there is [somewhere] a "safety mechanism" imposed by some nanny-state buffoon, and that this is so easily defeated by adding a spurious WHERE clause. Ditto that I had never hit that speed-bump, so I apologise for reacting with horror/disbelief to your "necessary" comment! |
update .. I have now found these gems that suggests this is a JetBrains client-side "help" so maybe not a server-side (MSSQL on-prem or Azure MI/etc cloud) problem afterr all. |
Could be that I was writing my docs SQL samples on Jetbrains... Please feel free to submit a quick PR removing that WHERE clause. |
thanks for admission; best larf I've had today. I have raised Issue #4060 and will leave you to clear up the doc +/- code mess actually I am relieved that the MSSQL wizards haven't been infiltrated by some woke nanny/PHB enforcing global equality & diversity (or in UK the Health & Safety nannies) As you & Arfur have dismissed my #4028 I feel like we have at least reached a 15-all deuce! |
docs at https://docs.microsoft.com/en-us/ef/core/testing/testing-with-the-database#efficient-database-creation debate when EnsureX is called (worrying about outdated schema). Surely this 1-off db drop+create could be best implemented in a static ctor since this must be executed [once] before any instance ctor is invoked ?
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: