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

Says Asynchronous Code should be used but DbInitializer.cs Example is Not Asynchronous #8214

Closed
robinwilson16 opened this issue Aug 21, 2018 — with docs.microsoft.com · 5 comments
Labels
Pri2 Source - Docs.ms Docs Customer feedback via GitHub Issue
Milestone

Comments

Copy link

The documentation says to always use asynchronous code yet the code given in DbInitializer.cs is synchronous.

The code should be re-written to use asynchronous methods (unless I am missing something).

This would involve changing commands from:

context.Student.Add(s);
context.SaveChanges();

To

await context.Student.AddAsync(s);
await context.SaveChangesAsync();

Either seems to work ok though and produce the desired result. Maybe as it only runs once during project startup it doesn't really matter?


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@Rick-Anderson
Copy link
Contributor

@robinwilson16 good suggestion. We hope to rewrite the initializer . See #8138

@Rick-Anderson Rick-Anderson added Pri1 Source - Docs.ms Docs Customer feedback via GitHub Issue labels Aug 21, 2018
@Rick-Anderson Rick-Anderson added this to the Backlog milestone Aug 21, 2018
@Rick-Anderson
Copy link
Contributor

@robinwilson16 given seeding the DB is a one-time operation for non-production code, simplicity/debugabilty is more important. I've had to debug seed code more than once.

@robinwilson16
Copy link
Author

Ok thanks Rick. I can see why it isn't needed there in that case.
Robin

@Rick-Anderson
Copy link
Contributor

Thanks for bringing this up. When we update the doc we'll explain why we're using synchronous.

@Rick-Anderson Rick-Anderson added Pri2 and removed Pri1 labels Jan 14, 2019
@Rick-Anderson
Copy link
Contributor

The DB initializer is only used early in project development, not in production code. It's OK to use Sync in this case since best perf is not a concern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pri2 Source - Docs.ms Docs Customer feedback via GitHub Issue
Projects
None yet
Development

No branches or pull requests

2 participants