Язык программирования C#9 и платформа .NET5
Часть 449 из 642 Информация о книге
.IgnoreQueryFilters().Where(x => x.Id == id).Include(m => m.MakeNavigation).FirstOrDefault();Добавьте метод, который позволяет получить значение
, используя хранимую процедуру:PetNamepublic string GetPetName(int id){var parameterId = new SqlParameter{ParameterName = "@carId",SqlDbType = SqlDbType.Int,Value = id,};var parameterName = new SqlParameter{ParameterName = "@petName",SqlDbType = SqlDbType.NVarChar,Size = 50,Direction = ParameterDirection.Output};_ = Context.Database.ExecuteSqlRaw("EXEC [dbo].[GetPetName] @carId, @petName OUTPUT",parameterId,parameterName);return (string)parameterName.Value;}Хранилище данных о кредитных рисках
Откройте файл класса
и поместите в его начало следующие операторыCreditRiskRepo.cs:usingusing AutoLot.Dal.EfStructures;using AutoLot.Dal.Models.Entities;using AutoLot.Dal.Repos.Base;using AutoLot.Dal.Repos.Interfaces;using Microsoft.EntityFrameworkCore;Измените класс на
, унаследуйте его отpublic, реализуйтеBaseRepo<CreditRisk>и добавьте два обязательных конструктора:ICreditRiskReponamespace AutoLot.Dal.Repos{<b>public</b> class CreditRiskRepo : <b>BaseRepo<CreditRisk>, ICreditRiskRepo</b>{public CreditRiskRepo(ApplicationDbContext context) : base(context){}internal CreditRiskRepo(DbContextOptions<ApplicationDbContext> options): base(options){}}}Хранилище данных о заказчиках
Откройте файл класса
и поместите в его начало приведенные далее операторыCustomerRepo.cs:usingusing 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>и добавьте два обязательных конструктора:ICustomerReponamespace AutoLot.Dal.Repos{<b>public</b> class CustomerRepo : <b>BaseRepo<Customer>, ICustomerRepo</b>{public CustomerRepo(ApplicationDbContext context): base(context){}internal CustomerRepo(DbContextOptions<ApplicationDbContext> options): base(options){}}}Наконец, добавьте метод, который возвращает все записи
с их заказами, отсортированные по значениямCustomer:LastNamepublic override IEnumerable<Customer> GetAll()=> Table.Include(c => c.Orders).OrderBy(o => o.PersonalInformation.LastName);Хранилище данных о производителях
Откройте файл класса
и поместите в его начало перечисленные ниже операторыMakeRepo.cs:usingusing 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