Показать сообщение отдельно
Старый 23.01.2017, 16:53   #5  
ax_mct is offline
ax_mct
Banned
 
2,548 / 1091 (0) ++++++++
Регистрация: 10.10.2005
Адрес: Westlands
Кажется этой ссылки еще не было:
https://blogs.msdn.microsoft.com/sav...series-part-5/
Цитата:
Although the number of insert calls remain 20k, the time fall down from 5 seconds to 1.5 seconds. Now we are more than 3 times faster than the naïve approach that calls the insert statement 20k times through a loop.
Цитата:
  • UnitOfWork must run on the server tie
  • The child must have a relation explicity defined in AOT to the parent
  • No record will be inserted into the database until the saveChanges method is called.
  • You can enjoy the methods: insertOnSaveChanges, deleteOnSaveChanges, updateOnSaveChanges, saveChanges
Фича, да. Но я бы не применял по умолчанию пока не поставлена отдельная задача по улучшению производительности и тогда рассматривал бы как одну из опций. Так как какие-то риски все равно есть, а в первоначальных решений их надо сводить к минимуму.

X++:
public static server void insertWithUnitOfWork()
{
    FooChild   child;
    FooParent  parent;

    // Instantiating the UnitOfWork.
    // Notice that this method runs on server
    UnitofWork unitOfWork = new unitOfWork();
    int i;

    for (i = 0; i < 10000; ++i)
    {
        parent.ParentId = int2str(i);
        parent.Name = 'Any name for parent' + int2str(i);
        parent.Description = 'Any description for parent' + int2str(i);

        child.ChildId = int2str(i);
        child.Name = 'Any name for child' + int2str(i);
        child.Description = 'Any description for child' + int2str(i);

        // You will just be able to call this method if there is a relation
        // called FooParent at FooChild table
        child.FooParent(parent);

        // Marking these buffers to be inserted by UnitOfWork
        // The buffers are not being inserted at the database right now.
        unitOfWork.insertonSaveChanges(parent);
        unitOfWork.insertonSaveChanges(child);
    }

    // Finally, asking UnitOfWork to insert the records at the database.
    unitOfWork.saveChanges();
}
За это сообщение автора поблагодарили: mazzy (2).