MicroLite-ORM / MicroLite

MicroLite ORM framework

Home Page:microliteorm.wordpress.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add overload for UpdateAsync method accepting Action<T>

djanosik opened this issue · comments

I found it useful to combine SingleAsync and UpdateAsync methods, especially when writing integration tests. It resulted in a method accepting two parameters - record identifier, and an action used update the record.

public async Task<bool> UpdateAsync<T>(object identifier, Action<T> update)
{
    var record = await SingleAsync<T>(identifier);

    if (record != null && update != null)
    {
        update(record);
        return await UpdateAsync(record);
    }

    return false;
}

The usage is straight-forward.

session.UpdateAsync<Record>(Id, r =>
{
    r.Description = "sdfsdfsdf";
});

This isn't something I'd like to see in the native API. However if it's something you want, you can easily create an extension method on IAsyncSession to do this if you want to.