Building the Data Access Layer
with Entity Framework Core
1/17/2018 JOYANTA KUMAR SARKER,CEAT,IUBAT 1
What I Know from the Chapter
• Navigation Properties and Foreign Keys
• Adding Product Model
• The Order Detail with Product Info View Model
• Adding the IProductRepo Interface
• Adding the Product Repository
• Initializing the Database with Data
1/17/2018 JOYANTA KUMAR SARKER,CEAT,IUBAT 2
Navigation Properties and Foreign Keys
• Public class blog{
Public int BlogID {get,get}
Public List<Post>Posts {get;set;}
}
Public class Post{
Public int BlogID {get;set;}
Public Blog Blog { get;set;}
}
1/17/2018 JOYANTA KUMAR SARKER,CEAT,IUBAT 3
Adding Product Model
using system.Collection.Generic;
Using system.ComponentModel.DataAnnotations;
Using system.ComponentModel.DataAnnotations.Schema;
Using SpyStore.Models.Entities.Base;
Namespace SpyStore.Models.Entities{
[Table(“Products”,Schema=“Store”)]
Public class Products : EntityBase
{………………..}
[InverseProperty(name of(OrderDetail.Product))]
Public List<OrderDetail>OrderDetails{get;set;}=new List<OrderDetails>();
}
}
1/17/2018 JOYANTA KUMAR SARKER,CEAT,IUBAT 4
The Order Detail with Product Info View Model
Using system.ComponentModel.DataAnnotations;
Using system.ComponentModel.DataAnnotations.Schema;
Using SpyStore.Models.Entities.Base;
Using SpyStore.Models.viewModels.Base;
Namespace Spystore.Models.ViewModels{
Public class OrderDetailWithProductInfo:ProductAndCategoryBase
{
Public int OrderID {get;set;}
[Required]
Public int Quantity {get;set;}
[DataType(DataType.Currency),Display(Name=“Total”)]
Public decimal?LineItemTotal{get;set;}
}
}
1/17/2018 JOYANTA KUMAR SARKER,CEAT,IUBAT 5
Full Entity Framework Core in 1 diagram
Adding Product
Model
The Order Detail
with Product Info
View Model
Adding the
IProductRepo
Interface
Adding the
Product
Repository
Initializing the
Database with
Data
1/17/2018 JOYANTA KUMAR SARKER,CEAT,IUBAT 6
1/17/2018 JOYANTA KUMAR SARKER,CEAT,IUBAT 7

Building the data access layer with entity framework

  • 1.
    Building the DataAccess Layer with Entity Framework Core 1/17/2018 JOYANTA KUMAR SARKER,CEAT,IUBAT 1
  • 2.
    What I Knowfrom the Chapter • Navigation Properties and Foreign Keys • Adding Product Model • The Order Detail with Product Info View Model • Adding the IProductRepo Interface • Adding the Product Repository • Initializing the Database with Data 1/17/2018 JOYANTA KUMAR SARKER,CEAT,IUBAT 2
  • 3.
    Navigation Properties andForeign Keys • Public class blog{ Public int BlogID {get,get} Public List<Post>Posts {get;set;} } Public class Post{ Public int BlogID {get;set;} Public Blog Blog { get;set;} } 1/17/2018 JOYANTA KUMAR SARKER,CEAT,IUBAT 3
  • 4.
    Adding Product Model usingsystem.Collection.Generic; Using system.ComponentModel.DataAnnotations; Using system.ComponentModel.DataAnnotations.Schema; Using SpyStore.Models.Entities.Base; Namespace SpyStore.Models.Entities{ [Table(“Products”,Schema=“Store”)] Public class Products : EntityBase {………………..} [InverseProperty(name of(OrderDetail.Product))] Public List<OrderDetail>OrderDetails{get;set;}=new List<OrderDetails>(); } } 1/17/2018 JOYANTA KUMAR SARKER,CEAT,IUBAT 4
  • 5.
    The Order Detailwith Product Info View Model Using system.ComponentModel.DataAnnotations; Using system.ComponentModel.DataAnnotations.Schema; Using SpyStore.Models.Entities.Base; Using SpyStore.Models.viewModels.Base; Namespace Spystore.Models.ViewModels{ Public class OrderDetailWithProductInfo:ProductAndCategoryBase { Public int OrderID {get;set;} [Required] Public int Quantity {get;set;} [DataType(DataType.Currency),Display(Name=“Total”)] Public decimal?LineItemTotal{get;set;} } } 1/17/2018 JOYANTA KUMAR SARKER,CEAT,IUBAT 5
  • 6.
    Full Entity FrameworkCore in 1 diagram Adding Product Model The Order Detail with Product Info View Model Adding the IProductRepo Interface Adding the Product Repository Initializing the Database with Data 1/17/2018 JOYANTA KUMAR SARKER,CEAT,IUBAT 6
  • 7.
    1/17/2018 JOYANTA KUMARSARKER,CEAT,IUBAT 7