Skip to content
This repository has been archived by the owner on Mar 17, 2020. It is now read-only.

Unable to include navigation properties when using EFCachedDbSet #65

Open
seroche opened this issue Jan 21, 2020 · 2 comments
Open

Unable to include navigation properties when using EFCachedDbSet #65

seroche opened this issue Jan 21, 2020 · 2 comments

Comments

@seroche
Copy link

seroche commented Jan 21, 2020

Summary of the issue

Calling Include on an EFCachedDbSet does not include the property as expected.

Environment

.NET Core SDK version: 3.1.1 (latest stable)
Microsoft.EntityFrameworkCore version: 3.1.1 (latest stable) 
EFSecondLevelCache.Core version: 2.9.1 (latest stable)

Example code/Steps to reproduce:

I'm using the following entity extracted from my MSSQL DB.

public class Category : Entity<string>
{
	public string Name { get; private set; }
	public string ParentCategoryId { get; private set; }
	public ICollection<Category> SubCategories { get; private set; }

	protected Category() { }
}

In EF Core, the binding is created as followed:

builder.Entity<Category>(m =>
{
	#region Mappings
	m.ToTable("Category", "social");

	m.Property(x => x.Id)
		.HasColumnName("CategoryId");

	m.HasKey(x => x.Id);

	m.HasMany(x => x.SubCategories)
		.WithOne()
		.HasForeignKey(x => x.ParentCategoryId);
	#endregion
});

Outputs

When I call the following code, SubCategories are all NULL.

db
.Set<Category>()
**.Cacheable(CacheExpirationMode.Absolute, TimeSpan.FromDays(7))**
**.Include(x => x.SubCategories)**
.ToListAsync(token);

If I move the include before the Cacheable(), then it works fine.

db
.Set<Category>()
**.Include(x => x.SubCategories)**
**.Cacheable(CacheExpirationMode.Absolute, TimeSpan.FromDays(7))**
.ToListAsync(token);

I assume it's related to #39. It would convenient if we could call the include on the EFCachedDbSet. This way we can keep the Cache mgt code within one class (the DbContext)

image

@Rayvid
Copy link

Rayvid commented Jan 23, 2020

The proxy class will never work after the entity retrieved from Cacheable. That's design limitation I imagine very hard to overcome.

My thoughts on this #63 I guess you need either quit using lazy loading, either wait for EFCore changes to be able to disable proxy creation on will

@VahidN
Copy link
Owner

VahidN commented Feb 15, 2020

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants