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

Getting started example does not work #3078

Closed
cmulka opened this issue Feb 4, 2021 · 8 comments · Fixed by #3079
Closed

Getting started example does not work #3078

cmulka opened this issue Feb 4, 2021 · 8 comments · Fixed by #3079
Assignees
Milestone

Comments

@cmulka
Copy link

cmulka commented Feb 4, 2021

I get a 'table blog does not exist' error and I verified the table was created correctly in the blogging.db. I've been trying to use sqlite with entity framework and I simply cannot get it to work. Not a fan of EF.


Document Details

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

@roji
Copy link
Member

roji commented Feb 4, 2021

The issue here is presumably that the dotnet ef creates the blogging.db at the project root, but the application tries to look for it in its current work directory, which is under bin/Debug/net5.0. @cmulka you can simply change the Data Source parameter to point to the absolute path of your database (e.g. options.UseSqlite(@"Data Source=c:\projects\EFDemo\blogging.db"));

To fix the sample, we should probably just use EnsureDeleted/EnsureCreated - this would also simplify the very first getting started experience (no need for Design, tools, migrations...). If we really want to do migrations in this sample, we could put an absolute path which the user would then need to change.

roji added a commit that referenced this issue Feb 4, 2021
Create the database with EnsureCreated instead of with Migrations.

Fixes #3078
@roji roji changed the title Example does not work Getting started example does not work Feb 4, 2021
@roji roji self-assigned this Feb 4, 2021
@ajcvickers
Copy link
Contributor

@roji

To fix the sample, we should probably just use EnsureDeleted/EnsureCreated

It is very much by-design that we don't do this, since it promotes a bad pattern. If the getting started using migrations doesn't work out of the box, then we really need to fix the experience rather than changing the getting started.

@roji
Copy link
Member

roji commented Feb 4, 2021

I would have thought that for initial application prototyping EnsureCreated is fine (after all it does exist), with full-on Migrations coming into play when the application first goes to production (at least that's what I did for my real-world EF app dev). I guess the question is whether we want a completely new user who knows nothing about EF to have to bother with migrations in their very first experience.

Anyway, we can put in an absolute path and instruct the user to modify it - or whatever else you think we should do.

@ajcvickers ajcvickers added this to the 6.0.0 milestone Feb 8, 2021
@roji
Copy link
Member

roji commented Feb 10, 2021

@ajcvickers and others, I looked again and dotnet run does in fact run: it's just that Rider suffers from the same issue as VS does, where the program starts up under bin/Debug/net5.0 (dotnet/project-system#3619). I guess it's probably more of an MSBuild issue that also affects Rider. Adding <StartWorkingDirectory> as documented for VS works around the issue for Rider too.

As we seem to have been OK with the VS workaround up to now, I guess this can simply be closed. On the other hand, it does seem like a pretty big wart on the very first getting started, so we can still just change the Sqlite database path to something like C:\blog\blogging.db and instruct the user to tweak that if they want to.

@roji roji removed this from the 6.0.0 milestone Feb 10, 2021
@roji roji removed the closed-fixed label Feb 10, 2021
@Rick-Anderson
Copy link
Contributor

Changing => options.UseSqlite("Data Source=blogging.db"); to
=> options.UseSqlite("Data Source=C:\blog\blogging.db"); seems to be a win-win.

In the ASP.NET Core repo, we get lots of question on where the DB is located.

@ErikEJ
Copy link
Contributor

ErikEJ commented Feb 11, 2021

@Rick-Anderson thinking back to SQL CE - exact same challenge!

roji added a commit that referenced this issue Feb 11, 2021
@roji
Copy link
Member

roji commented Feb 11, 2021

Modified #3079 to specify options.UseSqlite("Data Source=C:\blogging.db").

@roji
Copy link
Member

roji commented Feb 11, 2021

Note that this solves the problem for Windows users, but on Linux and Mac C:\blogging.db is just another relative path, so the same problem exists there (e.g. Rider on Linux).

@ajcvickers ajcvickers added this to the 6.0.0 milestone Feb 19, 2021
roji added a commit that referenced this issue Feb 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants