Updating an already fetched collection through update multi

Posts   
 
    
e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 26-Mar-2012 04:30:55   

Is it possible to update an already fetched collection through UpdateMulti? i have tried the following but seems like it is not working:

public static void UpdateIsNotificationSentStatusOfStaffEmploymentDocuments(StaffEmploymentDocumentCollection docsToExpire, StaffEmploymentDocumentCollection expiredDocs) { var toUpdate1 = new StaffEmploymentDocumentEntity { IsNotificationSentXdaysBeforeExpirationDate = true }; docsToExpire.UpdateMulti(toUpdate1, null);

        var toUpdate2 = new StaffEmploymentDocumentEntity { IsNotificationSentAfterExpirationDate = true };
        expiredDocs.UpdateMulti(toUpdate2, null);
    }

If this is the wrong way what would be the best way without looping through each collection item and updating each one individually.

thanks -shane

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Mar-2012 09:05:00   

UpdateMulti() is used to update entities in the database, not in memory. So the collection used with UpdateMulti() is just used to know which table the update command should be issued, regardeless of the entities inside the collection. And you shouold use a filter, if you want to limit the entities being updated in the database.

To update entities in a collection in memory, you'll need to loop on them. And then if you need to save these changes back to the database, all you need to do is call SaveMulti() on the collection.

e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 26-Mar-2012 20:11:22   

thank you. that helps.

Walaa wrote:

UpdateMulti() is used to update entities in the database, not in memory. So the collection used with UpdateMulti() is just used to know which table the update command should be issued, regardeless of the entities inside the collection. And you shouold use a filter, if you want to limit the entities being updated in the database.

To update entities in a collection in memory, you'll need to loop on them. And then if you need to save these changes back to the database, all you need to do is call SaveMulti() on the collection.