Skip to content

Data-driven ASP.NET Core Application with EF Core - App to manage pie's

Notifications You must be signed in to change notification settings

kadisin/PieShopAdmin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Admin Pie Shop

image

Description (business perspective):

Web application use to manage pies.

As a owner of pie shop I want to manage a pies, categories (of pies) and orders.

Description (technical perspective)

Web application use to manage pies

Project architecture:

MVC architecture with extension using repository pattern

Architecture diagram

arch

Operations on pie's and categories (look interfaces IPieRepository and ICategoryRepository).

Pie:

  • Get all
  • Get by Id
  • Add pie
  • Update pie
  • Remove pie
  • Search pie (get pies with filter)
  • Category:

  • Get all
  • Get by Id
  • Add category
  • Update category
  • Delete category
  • Project to learn good practises using Entity framework

  • Code first design
  • Dependency Injection
  • IQueryable vs IEnumerable
  • Track changes
  • Cache
  • Migrations
  • Database structure:

    image

    Intresting notes:

    Track changes: This is one of the main function on Entity framework.

    EF track changes on rows (add, modify, delete)

    Changes are related to existing object DbContext

    var entries = context.ChangeTracker.Entries();

    foreach (var entry in entries) { Console.WriteLine("Entity Name: {0}", entry.Entity.GetType().Name); Console.WriteLine("Status: {0}", entry.State); }

    Entity Name: Student Status: Unchanged

    Entity Name: Enrollment Status: Added

    When we only load data to see on page (Categories to dropdown) then we could use AsNoTracking() method

    IEnumerable vs IQueryable

    IEnumerable load all data from database to memory then filter it

    IEnumerable employeeIEnumberable = db.Employee.Where(a =>; a.JobTitle.StartsWith("P")); employeeIEnumberable = employeeIEnumberable.Take(5)

    Looks in sql: select * from HumanResources.Employee where JobTitle like 'P%'

    IQueryable filtering data on database then load to application

    IQueryable employeeIQueryable = db.Employee.Where(a => a.JobTitle.StartsWith("P")); employeeIQueryable = employeeIQueryable.Take(5)

    Looks in sql: select top(5) * from HumanResources.Employee where JobTitle like 'P%'

    IQueryable is optymalization on database side

    In-memory Caching

    Using IMemoryCache - stores data in memory server

    Set and use cache basicly on get data (load data to memory)

    Remove cache on add, update, delete data