53 lines
1.7 KiB
Plaintext
53 lines
1.7 KiB
Plaintext
HOW TO CREATE: EF CORE PROJECT
|
|
==============================
|
|
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 core, not standard
|
|
this can be a problem b/c standard and framework can only reference standard, not core
|
|
TO USE MIGRATIONS (core and/or standard)
|
|
add to csproj
|
|
<PropertyGroup>
|
|
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
|
|
</PropertyGroup>
|
|
TO USE MIGRATIONS AS *BOTH* CORE AND STANDARD
|
|
edit csproj
|
|
pluralize this xml tag
|
|
from: TargetFramework
|
|
to: TargetFrameworks
|
|
inside of TargetFrameworks
|
|
from: netstandard2.1
|
|
to: netcoreapp3.0;netstandard2.1
|
|
|
|
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
|
|
|
|
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/ |