问题
When I run
Scaffold-DbContext "Filename=mydatabase.sqlite3" Microsoft.EntityFrameworkCore.Sqlite
I get an empty context
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
namespace MyNamespace
{
public partial class mydatabaseContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite(@"Filename=mydatabse.sqlite3");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
}
}
}
Am I doing something wrong. Is this available for SQLite?
I have a single table in the database with id and name, just a simple example to get me going.
回答1:
It is creating a new database in bin folder because of the relative path in the connection string. I used new connection string.
Scaffold-DbContext "DataSource=C:\dev\mydatabase.sqlite3" Microsoft.EntityFrameworkCore.Sqlite
回答2:
Paths are resolved relative to the output directory. (a.k.a. bin
.) Ensure your database file is copied to the output directory on build.
Do this in csproj by setting Copy to Output Directory to Copy if newer.
Do this on xproj by adding the following to your project.json
.
{
"publishOptions": {
"include": [
"mydatabase.sqlite"
]
}
}
回答3:
you can try:
Scaffold-DbContext "DataSource=PATH\mydatabase.sqlite3 "Microsoft.EntityFrameworkCore.Sqlite -OutputDir Models
来源:https://stackoverflow.com/questions/37984456/sqlite-scaffolding-with-entity-framework-core