I hove over the DBContent class and shows that is coming from Microsoft.EntityFrameworkCore which means that I'm using EF Core as I suspected.
Yet. I'm still uncertain about the following:
How it come that the Nuget Package Manager is saying that the Frameworkcore isn't installed when I browse it ? My quess is that by installing Microsoft.AspnetCore packages I indirectly installed the framework ???
Now knowing that we have the EF Core, the initial question still remains why the lazy loading is performed. I'm putting again the code in full so you can see whether I'm missing something here .
public class GenericRRepository<T> : IGenericRepository<T> where T : class
{
protected HousingContext _context;
private readonly IUnitOfWorkAsync _unitOfWork;
public GenericRRepository(HousingContext context)
{
_context = context;
1) Getlist method doesn't call the include property hence I'm not doing eager loading. when the code runs EF core load all the related data referred in the navigation properties ...according to Microsoft documentation this happens when this option is enabled
which isn't the case as I checked thoroughly already.
In short, knowing that EF core is installed and the lazy loading option hasn't been activated, all together gives me the impression that there is something missing that could explain why the Nuget Package Manager dosen't recognized the EF core in its browse
as an installed package ...
Member
21 Points
99 Posts
Re: Problems Disabling Lazy Loading in Asp.net core
Jan 14, 2021 03:39 PM|9peculiar|LINK
Hi Patrice:
I hove over the DBContent class and shows that is coming from Microsoft.EntityFrameworkCore which means that I'm using EF Core as I suspected.
Yet. I'm still uncertain about the following:
How it come that the Nuget Package Manager is saying that the Frameworkcore isn't installed when I browse it ? My quess is that by installing Microsoft.AspnetCore packages I indirectly installed the framework ???
Now knowing that we have the EF Core, the initial question still remains why the lazy loading is performed. I'm putting again the code in full so you can see whether I'm missing something here .
public class GenericRRepository<T> : IGenericRepository<T> where T : class
{
protected HousingContext _context;
private readonly IUnitOfWorkAsync _unitOfWork;
public GenericRRepository(HousingContext context)
{
_context = context;
_unitOfWork = new UnitOfWorkAsc(context);
}
public IQueryable<T> Getlist(Expression<Func<T, bool>> filter = null, Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null, string includeProperties = "", int? page = null,
int? pageSize = null)
{
IQueryable<T> query = _context.Set<T>();
if (filter != null)
{
query = query.Where(filter);
}
if (orderBy != null)
{
query = orderBy(query);
}
if (includeProperties != null)
{
foreach (
var includeProperty in includeProperties.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
query = query.Include(includeProperty);
}
}
if (page != null && pageSize != null)
{
query = query.Skip((page.Value - 1) * pageSize.Value).Take(pageSize.Value);
}
return query.AsQueryable();
}
}
Controller
public async Task<IActionResult> Index(, int? Id = null)
{
IQueryable<ContractViewModel> query = _UoW.Repository<Contracts>().Getlist().Select(f => new ContractViewModel
{
Project = f.ProjectNavigation.Project,
Company = f.IdCompanyNavigation.Companyname,
Office=f.ProjectNavigation.DistrictOfficeNavigation.Office,
Project_Manager=f.ProjectNavigation.AssignedProjectManagerNavigation.Fullname,
Id = f.Id,
Value = f.ContractValue,
Contigencies = f.Contigencies,
Total_Contract_Value = f.Total,
Contractual_Committment = f.ContractAmounts.Sum(y => y.ContractBreakdownAmount) ?? 0,
Expenditure_to_Date =(decimal)f.ContractAmounts.SelectMany(k=>k.Invoices).Sum(p=>p.TotalCostToEmployer),
Description = f.Contractdescription
});
}
1) Getlist method doesn't call the include property hence I'm not doing eager loading. when the code runs EF core load all the related data referred in the navigation properties ...according to Microsoft documentation this happens when this option is enabled which isn't the case as I checked thoroughly already.
In short, knowing that EF core is installed and the lazy loading option hasn't been activated, all together gives me the impression that there is something missing that could explain why the Nuget Package Manager dosen't recognized the EF core in its browse as an installed package ...
Any hint from you ?