How to make lazy-loading work with EF Core 2.1.0 and proxies

前端 未结 3 612
北海茫月
北海茫月 2020-12-29 07:48

I have the following models:

public class Session
{
    public int SessionID { get; set; }
    public int UserID { get; set; }

    public virtual User User          


        
3条回答
  •  清酒与你
    2020-12-29 08:19

    You can try to configure proxies in Startup.cs like

    public void ConfigureServices(IServiceCollection services)
    {
        #region Database configuration
    
        // Database configuration
        services.AddDbContext(options =>
            options.UseLazyLoadingProxies()
                .UseSqlServer(Configuration.GetConnectionString("MyConnectionString")));
    
        #endregion Database configuration
    }
    

    And by the way you can already update you app packages to pure 2.1.0 (not final or RC). One of the reasons why your configuration may not work is an unstable version of components.

    NB: Microsoft.EntityFrameworkCore.Proxies.dll is installed from nuget independently from EFCore

提交回复
热议问题