Error in Fetch(Key):Lazy-Load Database

Error in fetch(key): lazy-load database in base R

This is an Rstudio problem with the current session, but there is an easy fix for it.

Simply restart your Rstudio!

Solution found here.

Failing to load the new ggplot2 in R

You should restart R after re-installing ggplot2. See the following Stackoverflow link as this is a similar problem

Error in fetch(key) : lazy-load database

Getting attempt was made to lazy-load navigation property on detached entity despite eager fetch

For posterity, here's the response from the EF Core team:

This is because lazy-loading isn't supported for NoTracking queries
(#10042) but we tried to not make it throw if it looked like
lazy-loading wasn't needed. In retrospect it might have been better to
always throw. Note that the warning can be configured to not throw
using ConfigureWarnings in the DbContextOptionsBuilder.

Just in case it's of use for someone, what I ended up doing was creating a second "ReadOnlyRepository" configured to not use lazy loading and to always return untracked sets. I use this repository for queries where I'm never going to persist changes to any of the entities, where the resultset can be large and when it needs to perform well.

public class ReadOnlyRepository : MainDbContextBase, IReadOnlyRepository
{
public ReadOnlyRepository(IConfigurationSettings configurationSettings)
: base(configurationSettings, false)
{
}

public IQueryable<T> Retrieve<T>() where T : class, IAmAnAggregateRoot
{
return GetDbSet<T>().AsNoTracking();
}
}

public class MainDbContextBase : DbContext
{
private readonly IConfigurationSettings configurationSettings;
private readonly bool useLazyLoading;

protected MainDbContextBase(IConfigurationSettings configurationSettings, bool useLazyLoading)
{
this.configurationSettings = configurationSettings;
this.useLazyLoading = useLazyLoading;
}

protected DbSet<T> GetDbSet<T>() where T : class
{
return Set<T>();
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder
.UseLazyLoadingProxies(useLazyLoading)
.UseSqlServer(configurationSettings.ConnectionString);
}
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
...
}
}

}



Related Topics



Leave a reply



Submit