-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiled model: Allow use of lazy loading and change tracking proxy types. #24902
Comments
Hi. Will we be able to CompiledModel with UseLazyLoadingProxies until the final version of .NET 6? |
@viniciusverasdossantos No, this issue is in the Backlog, so we don't have plans for shipping it in any specific release yet |
I am suffering a lot with my 550 entity model in development due to the delay each time I compile. I use lazyload and changetrackproxy. For Lazy Load if I implement the manual form in each class I will be able to use the CompiledModel right? Is there a similar alternative for ChangeTrackProxy? Well, I use both resources. |
@viniciusverasdossantos You might be hitting #20135, where proxy type creating is taking longer for each type. For change tracking you can implement INotifyPropertyChanging and INotifyPropertyChanged. |
Hi. Will we be able to CompiledModel with UseLazyLoadingProxies until the final version of .NET 7? |
@viniciusverasdossantos This issue is in the Backlog milestone. This means that it is not planned for the next release (EF Core 7.0). We will re-assess the backlog following the this release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources. Make sure to vote (👍) for this issue if it is important to you. |
This is very slow development on my model with more than 600 entities. I really hope this feature because it's a huge job to refactor all entities to get the compiled model. Thanks |
Part of #626 Part of #15911 Fixes #20135 Fixes #14554 Fixes #24902 This is the lowest level of materialization interception--it allows the actual constructor/factory binding to be changed, such that the expression tree for the compiled delegate is altered. Introduces singleton interceptors, which cannot be changed per context instance without re-building the internal service provider. (Note that we throw by default if this is abused and results in many service providers being created.) The use of this for proxies has two big advantages: - Proxy types are created lazily, which vastly improves model building time for big models with proxies. See #20135. - Proxies can now be used with the compiled model, since the proxy types are not compiled into the model. See
Part of #626 Part of #15911 Fixes #20135 Fixes #14554 Fixes #24902 This is the lowest level of materialization interception--it allows the actual constructor/factory binding to be changed, such that the expression tree for the compiled delegate is altered. Introduces singleton interceptors, which cannot be changed per context instance without re-building the internal service provider. (Note that we throw by default if this is abused and results in many service providers being created.) The use of this for proxies has two big advantages: - Proxy types are created lazily, which vastly improves model building time for big models with proxies. See #20135. - Proxies can now be used with the compiled model, since the proxy types are not compiled into the model. See
thank you very much |
I'm using the latest 7.0.1 version of the Microsoft.EntityFrameworkCore.Design, .Proxies and .Relational packages, and have installed the latest 7.0.1 version of the dotnet-ef tool. I've spent the past few days trying to get Lazy Loading proxies to work with the compiled model, without having any luck. Adding .UseModel() to the options builder always results in the poco entity class being returned from EF queries, instead of the Castle proxy. The What's New In EF Core 7.0 page claims that Lazy Loading proxies now work with Compiled Models, and I was hoping you could share any insights for setting it up?
|
@dneeper It's working for me--see my test code below. If you're still running into an issue, then please open a new issue and attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate. public class Blog
{
public int Id { get; set; }
public virtual List<Post> Posts { get; } = new();
}
public class Post
{
public int Id { get; set; }
public int? BlogId { get; set; }
public virtual Blog? Blog { get; set; }
}
public class SomeDbContext : DbContext
{
public DbSet<Blog> Blogs => Set<Blog>();
public DbSet<Post> Posts => Set<Post>();
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseModel(SomeDbContextModel.Instance)
.UseLazyLoadingProxies()
.UseSqlServer(@"Data Source=(LocalDb)\MSSQLLocalDB;Database=AllTogetherNow")
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
}
public class Program
{
public static async Task Main()
{
using (var context = new SomeDbContext())
{
// await context.Database.EnsureDeletedAsync();
// await context.Database.EnsureCreatedAsync();
context.Add(new Post { Blog = new() });
await context.SaveChangesAsync();
}
using (var context = new SomeDbContext())
{
var post = context.Posts.First();
Console.WriteLine(post.GetType());
Console.WriteLine(post.Blog!.Id);
}
}
} |
@dneeper It didn't work for us at first either. Then realized in production we called |
I did find my problem - I was setting the options and creating the context in the ContextFactory, but, I needed to call |
Hi @dneeper , can you help me with the code? |
If this issue is resolved, documentation should be updated here: https://learn.microsoft.com/en-us/ef/core/performance/advanced-performance-topics?tabs=with-di%2Csimple-with-parameter#limitations-1 |
Depends on #24898
The text was updated successfully, but these errors were encountered: