Question

I have a Device with a list of other DeviceLogEntry. device.Logs is a navigational property and I currently add new logs like so

device.Logs.Add(newEntry);     

Logs is defined as so

public virtual ICollection<DeviceLogEntry> Logs { get; set; }

My question is will this load the entire Logs table before adding the new one? If so (this would be really slow as Logs contains LOTS of entries). What would be a better (faster) alternative?

Was it helpful?

Solution

Looks like it is an issue they aren't fixing just now: http://entityframework.codeplex.com/workitem/683

Couple of things you could try.

  1. Disable lazy loading for the entity by removing virtual
  2. Do the addition the other way around if applicable

For point 2, would be a case of exposing the DeviceId on your log table, and instead of doing:

device.Logs.Add(newEntry);  

would to do something like:

newEntry.DeviceId = _deviceId;
context.Logs.Add(newEntry);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top