This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Saving many entities to the database seems quite slow. Is there anything we can do to make this faster? Here is a screenshot of a profiler when saving 2000 entities to the database: |
|
|
Most of what you are seeing in that trace is wire-up of the associated entities to the UnitOfWork when calling UnitOfWork.Add(entity). Note that this is not actually saving anything to the database but enlisting the objects in the UnitOfWork. The changes are persisted to the database when you call UnitOfWork.SaveChanges(). If your StoreDealInDatabase method also contains this call then presumably that part of it is taking (161.223 - 159.936) 1.287ms or less so that part of it seems like its executing quickly. All entities need to be enlisted in the UnitOfWork for consistency (e.g. Do we need to persist any of the associated objects because they are also new?) but if your use-case is one where you are adding an entity and associating it to an existing entity then you can avoid the need for the added wire-up calls by determining the Id of the associated entity and then assigning the association by Id - e.g. if your association was called Foo then you would assign FooId to be the Id of the associated entity. One wrinkle to this is that if the associated entity is already loaded in the UnitOfWork then wire-up of the entity itself will still occur when you assign by Id, but this will effectively be a no-op as we shortcut on checking if its already attached to the UnitOfWork. Would that match with what you are doing leading up to calling UnitOfWork.Add() in this instance?
|
|