문제

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.

  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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top