[Test]
public void FkManipulationTest()
{
EntityCollection orders = new EntityCollection(new OrderEntityFactory());
using(DataAccessAdapter adapter = new DataAccessAdapter())
{
adapter.FetchEntityCollection(orders, null);
}
Console.WriteLine("Start of manipulation of {0} entities", orders.Count);
DateTime start = DateTime.Now;
foreach(OrderEntity order in orders)
{
order.EmployeeId++;
}
DateTime end = DateTime.Now;
Console.WriteLine("End of manipulation");
TimeSpan delta = end.Subtract(start);
Console.WriteLine("{0}", (delta.TotalMilliseconds / 1000.0f));
EntityCollection orders2 = new EntityCollection(new OrderEntityFactory());
for (int i = 0; i < 818; i++)
{
orders2.Add(new OrderEntity());
}
start = DateTime.Now;
foreach(OrderEntity order in orders)
{
order.EmployeeId++;
}
end = DateTime.Now;
Console.WriteLine("End of manipulation");
delta = end.Subtract(start);
Console.WriteLine("{0}", (delta.TotalMilliseconds / 1000.0f));
}
prints 0.3 seconds. (818 entities). In a unittest through testdriven.net, so a little overhead here and there, debug build.
The empty entity manipulation also displays this. EmployeeId is an fk.
WHen I follow the SetNewFieldValue in the generated code, I then call into PostFieldValueSetAction, which raises EntityContentsChanged, which is then picked up by the collection, which then tries to raise a ListChanged event. Though as nothing is bound to that event, nothing happens. I then end up in OnEmployeeIdChanged though also nothing is bound to that event (EmployeeIdChanged), so I don't go anywhere but continue with the next iteration.
Often when a slowdown happens in an event producing routine, it's due to the fact that the event ends up in an expensive routine, like updating a grid or something.