Git Product home page Git Product logo

orm-and-dapper-exercise's Introduction

Exercise One

Taking what we’ve learned in class, implement Dapper inside this application.

We’ll start with Departments:

  1. Ignore appsettings.json file in .gitignore and commit
  2. Create appsettings.json in netcoreapp folder 3.Run a git status to make sure appsettings is ignored
  3. Add the MySql.Data Nuget Package
  4. Add the Dapper Nuget package
  5. Add the Microsoft.Extensions.Configuration.Json Nuget package
  6. Make sure your config code is in your main method
var config = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json")
                .Build();

string connString = config.GetConnectionString("DefaultConnection");

IDbConnection conn = new MySqlConnection(connString);
  1. Create a Department class 9.Create an IDepartmentRepository interface
  2. Create a DapperDepartmentRepository class
  3. Create a GetAllDepartments Method
  4. Create an InsertDepartment Method

Once finished, save, commit, and push back to Github

Exercise Two

  1. Create a public Product Class - this class will contain public properties that represent each column in the Products table.
// For example:
public int ProductID { get; set; }
  1. Create a IProductRepository Interface - this interface will have:
    • A GetAllProducts() method:
        IEnumerable<Product> GetAllProducts();
    
    • A CreateProduct(string name, double price, int categoryID) method:
    void CreateProduct(string name, double price, int categoryID);
    
  2. Create a DapperProductRepository Class that conforms to the IProductRepository interface. Here we will define our Methods.

4.Implement our new methods in the Main method of Program.cs

Bonus:

Create the UpdateProduct method in the DapperProductRepository class and implement in Program.cs

Extra Bonus:

Create the DeleteProduct method HINT: You will need to delete records from the Sales table and the Reviews table where that Product may be referenced. You can do this all in the DeleteProduct method you are creating

Finished Version: https://github.com/mvdoyle/BestBuyBestPractices

orm-and-dapper-exercise's People

Contributors

jshudd avatar mvdoyle avatar schwenk-a 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.