Found the answer!
It was because not all of my properties were marked virtual, and I was using List instead of Collection.
:)
Pregunta
This question is specifically for the EMS nopcommerce. When I look at the EF implementation in EFRepository
https://nopcommerce.codeplex.com/SourceControl/latest#src/Libraries/Nop.Data/EfRepository.cs
I see that the there is a property
protected virtual IDbSet<T> Entities
{
get
{
if (_entities == null)
_entities = _context.Set<T>();
return _entities;
}
}
I can see the entity is being set to the context. What I can't see is how the reference navigation properties are being set? Any foreign relationships will not be set to the context right??
Solución 2
Found the answer!
It was because not all of my properties were marked virtual, and I was using List instead of Collection.
:)
Otros consejos
This construct is just a lazy initialization of the repository's core member: _entities
, a DbSet<T>
. It doesn't matter whether _entities
is initialized there or in the repository's constructor. It just ensures Entities
will never return null. No other objects are set yet.
Not before you execute a LINQ query against Entities
are entities materialized and attached to the context. For instance
var rep = new EfRepository<Customer>();
var customers = rep.Entities.Include(c => c.Job).ToList();
Now Customer
s and their Job
s are loaded from the database and attached to the context.