Code Monkey home page Code Monkey logo

csharp-entity-framework-intro's Introduction

C# Entity Framework Intro

  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!

Exercise

Complete the LibraryRepository.cs. Finish all methods, replacing "throw new NotImplementedException();" with relevant C# Entity Framework code by using the LibraryContext.

Extension

Add a Publisher Model with propertyies Id(int) and Name(string), a PublisherController (if you can create in a similar way to AuthorApi.cs/BookApi.cs then great!
otherwise create in the usual way in the Controllers folder.), update ILibraryRepository, LibraryRepository and LibraryContext
and any other place you feel relevant to wire in the Publisher into the project. Don't forget to link the Publisher by Id as a foreign key to the Book object (decorate accordingly!).

In the Seed class populate the db by using the context class (hopefully you added a new Publisher DbSet in the Context) with some test data. You can call the GeneratePublisherName() to generate a name or make up your own version of this. As each publisher is added to the book object you should populate before the book population code, then randomly create a publisher for a book (tip.. use a similar approach to the book.AuthorId = authors[authorRandom.Next(authors.Count)].Id);)

csharp-entity-framework-intro's People

Contributors

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