Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DBContext does not contain a definition for Entry: Cannot load related data

When trying to load related data and following the guide on Explicit Loading of Related Data, I get the following error:

IApplicationDbcontext does not contain a definition for Entry.

My example code, similar to theirs, includes:

var person = _context.Persons.Single(p => p.PersonId = id);
_context.Entry(person).Collection(p => p.Addresses).Load();

The difference in my case is that I am injecting an IApplicationDbContext which looks pretty standard and I assume doesn't make a difference:

public class ApplicationDbContext : DbContext, IApplicationDbContext
{
   ...
   public DbSet<Person> Persons { get; set; }
   public DbSet<Address> Addresses { get; set; }
   ...
}

I have Microsoft.EntityFrameworkCore 5.0.7 within this project.

like image 336
8protons Avatar asked Dec 06 '25 20:12

8protons


1 Answers

Your IApplicationDbContext must declare the following method signiture in it in order to work.

EntityEntry<TEntity> Entry<TEntity>([NotNullAttribute] TEntity entity) where TEntity : class;
like image 74
Yazan Ati Avatar answered Dec 08 '25 10:12

Yazan Ati



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!