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?
Looks like it is an issue they aren't fixing just now: http://entityframework.codeplex.com/workitem/683
Couple of things you could try.
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);