48 lines
1.6 KiB
Plaintext
48 lines
1.6 KiB
Plaintext
HOW TO CREATE: EF CORE PROJECT
|
|
==============================
|
|
easiest with .NET Core but there's also a work-around for .NET Standard
|
|
example is for sqlite but the same works with MsSql
|
|
|
|
|
|
nuget
|
|
Microsoft.EntityFrameworkCore.Tools (needed for using Package Manager Console)
|
|
Microsoft.EntityFrameworkCore.Sqlite
|
|
|
|
MIGRATIONS require standard, not core
|
|
using standard instead of core. edit 3 things in csproj
|
|
1of3: pluralize xml TargetFramework tag to TargetFrameworks
|
|
2of2: TargetFrameworks from: netstandard2.0
|
|
to: netcoreapp2.1;netstandard2.0
|
|
3of3: add
|
|
<PropertyGroup>
|
|
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
|
|
</PropertyGroup>
|
|
|
|
run. error
|
|
SQLite Error 1: 'no such table: Blogs'.
|
|
|
|
set project "Set as StartUp Project"
|
|
|
|
Tools >> Nuget Package Manager >> Package Manager Console
|
|
default project: Examples\SQLite_NETCore2_0
|
|
|
|
note: in EFCore, Enable-Migrations is no longer used. start with add-migration
|
|
PM> add-migration InitialCreate
|
|
PM> Update-Database
|
|
|
|
if add-migration xyz throws and error, don't take the error msg at face value. try again with add-migration xyz -verbose
|
|
|
|
new sqlite .db file created: Copy always/Copy if newer
|
|
or copy .db file to destination
|
|
|
|
relative:
|
|
optionsBuilder.UseSqlite("Data Source=blogging.db");
|
|
absolute (use fwd slashes):
|
|
optionsBuilder.UseSqlite("Data Source=C:/foo/bar/blogging.db");
|
|
|
|
|
|
REFERENCE ARTICLES
|
|
------------------
|
|
https://docs.microsoft.com/en-us/ef/core/get-started/netcore/new-db-sqlite
|
|
https://carlos.mendible.com/2016/07/11/step-by-step-dotnet-core-and-entity-framework-core/
|
|
https://www.benday.com/2017/12/19/ef-core-2-0-migrations-without-hard-coded-connection-strings/ |