Язык программирования C#9 и платформа .NET5
Шрифт:
using AutoLot.Dal.EfStructures;
using AutoLot.Dal.Models.Entities;
using AutoLot.Dal.Repos.Base;
using AutoLot.Dal.Repos.Interfaces;
using Microsoft.EntityFrameworkCore;
Измените класс на
public
, унаследуйте его от BaseRepo<CreditRisk>
, реализуйте ICreditRiskRepo
и добавьте два обязательных конструктора:
namespace AutoLot.Dal.Repos
{
public class CreditRiskRepo : BaseRepo<CreditRisk>, ICreditRiskRepo
{
public CreditRiskRepo(ApplicationDbContext context) : base(context)
{
}
internal CreditRiskRepo(
DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
}
Хранилище
данных о заказчиках
Откройте файл класса
CustomerRepo.cs
и поместите в его начало приведенные далее операторы using
:
using System.Collections.Generic;
using System.Linq;
using AutoLot.Dal.EfStructures;
using AutoLot.Dal.Models.Entities;
using AutoLot.Dal.Repos.Base;
using AutoLot.Dal.Repos.Interfaces;
using Microsoft.EntityFrameworkCore;
Измените класс на
public
, унаследуйте его от BaseRepo<Customer>
, реализуйте ICustomerRepo
и добавьте два обязательных конструктора:
namespace AutoLot.Dal.Repos
{
public class CustomerRepo : BaseRepo<Customer>, ICustomerRepo
{
public CustomerRepo(ApplicationDbContext context)
: base(context)
{
}
internal CustomerRepo(
DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
}
Наконец, добавьте метод, который возвращает все записи
Customer
с их заказами, отсортированные по значениям LastName
:
public override IEnumerable<Customer> GetAll
=> Table
.Include(c => c.Orders)
.OrderBy(o => o.PersonalInformation.LastName);
Хранилище данных о производителях
Откройте файл класса
MakeRepo.cs
и поместите в его начало перечисленные ниже операторы using
:
using System.Collections.Generic;
using System.Linq;
using AutoLot.Dal.EfStructures;
using AutoLot.Dal.Models.Entities;
using AutoLot.Dal.Repos.Base;
using AutoLot.Dal.Repos.Interfaces;
using Microsoft.EntityFrameworkCore;
Измените класс на
public
, унаследуйте его от BaseRepo<Make>
, реализуйте IMakeRepo
и добавьте два обязательных конструктора:
namespace AutoLot.Dal.Repos
{
public class MakeRepo : BaseRepo<Make>, IMakeRepo
{
public MakeRepo(ApplicationDbContext context)
: base(context)
{
}
internal MakeRepo(
DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
}
Переопределите методы
GetAll
, чтобы они сортировали значения Make
по названиям:
public override IEnumerable<Make> GetAll
=> Table.OrderBy(m => m.Name);
public override IEnumerable<Make> GetAllIgnoreQueryFilters
=> Table.IgnoreQueryFilters.OrderBy(m => m.Name);
Хранилище данных о заказах
Откройте файл класса
OrderRepo.cs
и поместите в его начало следующие операторы using
:
using AutoLot.Dal.EfStructures;
using AutoLot.Dal.Models.Entities;
using AutoLot.Dal.Repos.Base;
using AutoLot.Dal.Repos.Interfaces;
using Microsoft.EntityFrameworkCore;
Измените класс на
public
, унаследуйте его от BaseRepo<Order>
и реализуйте IOrderRepo
:
namespace AutoLot.Dal.Repos
{
public class OrderRepo : BaseRepo<Order>, IOrderRepo
{
public OrderRepo(ApplicationDbContext context)
: base(context)
{
}
internal OrderRepo(
DbContextOptions<ApplicationDbContext> options)
Поделиться с друзьями: