Skip to content

truecodersio/ORM-and-Dapper-Exercise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

.NET template project for the ORM and Dapper exercise at TrueCoders

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages