I have a strange problem, when I try to use ObjectSet(TEntity).AddObject() to add a new Entity it is very slow compared to the normal behavior, it takes like 500ms and it happens just in one occasion and I am sure that the instruction which take some time is the AddObject and not the SaveChanges.
The code is very simple
ObjectEntity obj = businessObj.ExtractEntityObj();
context.ObjectTable.AddObject(ObjectEntity);
I do some work to the ObjectContext before to call this part of code but it’s not much more than what I do in all the other operations, It seems that it depends on how many items with the same foreign key are stored in database, I know it could sound weird but it’s the only variable that makes change the performance of this same instruction. I have also noticed that if I try that on a new DataContext the performance goes back to normal (few milliseconds) but for architectural problem I can’t have new DataContext each time I have to accomplish something.
Could someone help me?
Thanks
I resolved my issue, maybe could be helpfull to someone, it was due to a simple query I was doing before that instruction, this one:
I still don’t know why but this instruction attaches all “ObjectTable” data to the context making it very slow, “ObjectTable” is also the same table in which I was adding the new entity.
Setting the ObjectQuery MergeOption to NoTracking I have resolved the problem
Bye