3
I have a class called Locker that has the following property :
public virtual ICollection<LockerReserve> Reserves { get; set; }
The problem is that Lockerreserve belongs to a different context than Locker. An exception is always made when I try to retrieve a Lockler, because he can’t get the list from Lockerreserve.
public Locker GetLockerById(int lockerId)
{
var lockers = _lockerContext.Lockers
.Where(b => b.LockerId == lockerId);
return lockers.FirstOrDefault();
}
It is possible for a class to have a list of a type that is not in its context in the Entity Framework ?
I don’t understand exactly what you want to do... Puts the code from where the exception is being thrown, I did not understand what would be recover in its context
– Ricardo
I put the method where the exception is thrown. When he goes to pick up a Locker from context gives error, as Locker has a list of Lockerreserve that belongs to another context. And I can’t put Lockerreserve in the same context as Locker, because it will also be accessed in other contexts.
– Ricardo Mendes
And how is the Locker object mapped to the bank? Because he doesn’t invent that Locker has a Lockerreserve, or you mapped it in hand or he created the context based on the bank. How’s that?
– Ricardo
I did the mapping by the same code. Locker has a collection of Lockerreserve and Lockerreserve has a Locker Id.
– Ricardo Mendes
And the Lockerreserve property is pointing to which table? Or is it pointing to nothing? I’m asking this lot of questions because the way to play one inside the other is by apend, If in context 1 the object does not exist then there is no way to apend it, understand?
– Ricardo