Skip to content

EF Core 10 - Compiled Model in combination with Lazy Loading is supported #5337

Description

@PvdSScab

Type of issue

Typo

Description

The limitations of using a compiled model states that it cannot be used in combination with lazy loading proxies, but I have tested this, and in EF Core 10 it works without any error. Is this an old limitation which was valid in earlier versions?

In Program.cs:
builder.Services.AddDbContext<MyContext>(options => options .UseSqlServer(builder.Configuration.GetConnectionString(nameof(MyContext))) .UseModel(MyContextModel.Instance).UseLazyLoadingProxies());

The entities (simplified):
public partial class User { public int Id { get; set; } public int CompanyId { get; set; } public virtual Company Company { get; set; } }
public partial class Company { ... }

Some LINQ somewhere in code:
Context.User.Where(w => w.Id == 1).Select(s => s.Company).FirstOrDefault();

It fetches the Company and the objects show they have a LazyLoader attached to them.

Page URL

https://learn.microsoft.com/en-us/ef/core/performance/advanced-performance-topics?tabs=with-di%2Cexpression-api-with-constant#limitations-1

Content source URL

https://github.com/dotnet/EntityFramework.Docs/blob/main/entity-framework/core/performance/advanced-performance-topics.md

Document Version Independent Id

e96b453f-0256-8bc9-bd21-1343f2fe246c

Platform Id

ada64a4c-83c3-6714-0fa4-d80a203f4349

Article author

@roji

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions