I have :
var c = cboCustomer.SelectedItem as Customer;
var t = cboTrailer.SelectedItem as Trailer;
using (var db = new CAPSContainer())
{
db.Attach(c); --> Tracker has now 1 entity
db.Attach(t); --> Tracker has now 2 entities
c.Trailers.Remove(t); --> Tracker has now 29! entities loaded
db.DeleteObject(t);
db.SaveChanges();
}
I am trying to understand how this loading / caching is working because I am having some other issues related to it, any ideas why the cached amount suddenly jumps?
I am using EF 5.0.
Your default configuration probably had LazyLoadingEnabled set. So child lists won’t get loaded until they are accessed, see this article for a more detailed explanation:
http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/reading-related-data-with-the-entity-framework-in-an-asp-net-mvc-application
By the way, if you just want to remove one without loading the lot, then you can use DeleteObject as Boomer said.