Giter Site home page Giter Site logo

csharp-ef-migrations's Introduction

C# Entity Framework Migrations

  1. Fork this repository
  2. Clone your fork to your machine
  3. Open the ef.intro.sln in Visual Studio
  4. Note: There are no controllers in this project!! A current way of writing endpoints is in the EndPoint directory. See How the AuthorApi.cs & BookApi.cs both are extension methods of the WebApplication class which is returned in the Program.cs from a builder.Build() call. This way we can call this to initialize from the extension method. See also how the data is populated via the Seed() method call. Note how we are randomly generating names of both authors & books!

Key Outcomes

Understand how to apply Entity Framework migrations, using the commands: add-migration, update-database, script-migration

Exercise

-Add the LibraryRepository.cs and any models/code from the previous exercise.
-Configure this project for a secure connecton to your Elephant SQL instance.
-Configure this project for Entity Framework migrations.
-Run an "Add-Migration InitialMigration" command to create a first migration.
-Add a ReleaseDate (Use DateTime type) property to the Book class. Ensure this is populated in the Seed method (TIP. you can't use the DateTime.Now to create the date as PostgreSQL requires a UTC date so use: DateTime.UtcNow
Run a "Add-Migration AddedReleaseDateToBook" to the project. Run the update-database to change the db. Note how you don't have any data in the Postgres instance, so you'll need to TRUNCATE TABLE Authors CASCADE (do this for all tables) to empty
the records, then rebuild your project which will load the data with the dates.

Extension

-Create a script-migration

csharp-ef-migrations's People

Contributors

uerbzr avatar thanasis1997 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.