This slide began discussing navigation properties and their role in EF model classes.That was followed with a brief discussion of handling display names,stored procedures,and user defined functions.
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
Building the data access layer with entity framework
1. Building the Data Access Layer
with Entity Framework Core
1/17/2018 JOYANTA KUMAR SARKER,CEAT,IUBAT 1
2. 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
3. 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
4. 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
5. 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
6. 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