GithubHelp home page GithubHelp logo

devel0 / skeleton-netcore-ef-code-first Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 183 KB

entity core code-first from console app

License: MIT License

C# 100.00%
csharp entity-framework-core code-first migrations database-diagram

skeleton-netcore-ef-code-first's Introduction

skeleton-netcore-ef-code-first

๐Ÿ‘‰ one-to-one, one-to-many, many-to-many code first relationship examples here

description

Shows how to create a code-first local db using sqlite but the same approach can applied using other backends.

prepare database context

managing migrations

Migrations in code-first db allow team of developers to work on the same db project each with their on local db and versioning their changes through commits that includes Migrations folder.

The first-est migration is done by a developer and acts as an entry point for the work on that database so other developers can add their code-first changes after that commit by adding further migrations including code and Migrations folder changes.

Because each migration has a timestamp in the filename there aren't conflict on these while the Migrations/LocalDbContextModelSnapshots.cs can be subjected to normal git conflicts in some circumnstances that can be resolved in the usual way. To reduce conflict situation, regular pulls could help.

first migrations

Install dotnet ef migrations tools:

dotnet tool install --global dotnet-ef

Create initial migration:

cd skeleton-netcore-ef-core-first
dotnet ef migrations add initial

Commit the initial migration ( I didn't added the initial migration for didactic purpose ).

update database

Create a migration doesn't imply the code-first materialize on database, in order to do that, issue:

dotnet ef database update

This command can be used also to revert a migration applied by specifying a name of a migration already applied and all migrations after that one specified will be reverted returning to a state of "pending".

Migrations can be removed, when are in pending state, one by one from tail using dotnet ef migrations remove.

run the app

dn run
Started with 0 records
add new one [newRecord1]
changes: SampleData {Id: -9223372036854774807} Added

migration tool summary

cmd description
dotnet ef migrations list list migrations showing which aren't yet applied (pending)
dotnet ef database update apply pending migrations
dotnet ef migrations add MIGRATION_NAME add migrations
dotnet ef migrations remove remove latest not yet committed migration
dotnet ef databse update MIGRATION_TO revert applied migration

clean architecture

To improve maintainability, modularity and separation of concerns in enterprise applications the Clean architecture should evaluated; there are many boiler plate templates available:

dotnet new search clean

how this project was built

dotnet new console -n skeleton-netcore-ef-code-first -f net7.0 --langVersion 11

cd skeleton-netcore-ef-code-first
dotnet add package Microsoft.EntityFrameworkCore.Design --version 7.0.5
dotnet add package Microsoft.EntityFrameworkCore.Sqlite --version 7.0.5

skeleton-netcore-ef-code-first's People

Contributors

devel0 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.