I working a project and i need use lazyloading i installed package and configure,query working but relationship columns returned null. How to i can use lazyloading?
Installed Microsoft.EntityFrameworkCore.Proxies(version 5.0.7)
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer("ConnectionString");
optionsBuilder.UseLazyLoadingProxies(true);
}
}
My Models(I make with DB First)
public partial class Customer
{
public Customer()
{
Orders = new HashSet<Order>();
}
public int CustomerId { get; set; }
public int? CompanyId { get; set; }
public string Name { get; set; }
public string LastName { get; set; }
public string FullName { get; set; }
public string Phone { get; set; }
public string Mail { get; set; }
virtual public Company Company { get; set; }
virtual public ICollection<Order> Orders { get; set; }
}
public partial class Company
{
public Company()
{
Customers = new HashSet<Customer>();
}
public int CompanyId { get; set; }
public string Name { get; set; }
public string TaxNumber { get; set; }
public virtual ICollection<Customer> Customers { get; set; }
}
Used Method:
public List<Customer> GetCustomers()
{
using (dbContext context = new dbContext())
{
return context.Customers.ToList();
}
}