What's New with Mendz.Data.ResultInfo

ResultInfo represents result information about a procedure call. It can store the input and output values. These information can be used, for example, to build messages after an operation or a series of operations completed. These messages can be used for logging, or for alerts and notification.

I first talked about ResultInfo in one of my Dapper series article back in May of this year. It was followed up by a review in June also of this year. Note that ResultInfo was originally in the Mendz.Library namespace.

ResultInfo has been moved in Mendz.Data. Besides the namespace change, ResultInfo is pretty much the same, adding only one new property called TotalCount. This compliments the existing AffectedCount property. Now, ResultInfo can be used to report back, for example, that the procedure SourceName read TotalCount of records, but the process affected only AffectedCount number of records.

In the Mendz.Data.Repository(.Async) CRUDS interfaces, one of the parameters in the method signatures is a List<ResultInfo>. This is useful when the SourceName procedure is called in a loop. The ResultInfo list can also be used to store the result information for each loop.

ResultInfo has a property List<List<ResultInfo>>. This is specially useful in sequenced or nested repository operations. It is designed to list the results while maintaining the call hierarchy.

public Order Update(Order model, 
    dynamic expansion = null, List<ResultInfo> result = null)
{
    try
    {
        DbDataContext.BeginTransaction();
        string spName1 = "OrderUpdate";
        ... prepare parameters ...
        int affectedCount = DbDataContext.Context.ExecuteQuery(spName1, ...);
        ResultInfo resultinfo = new ResultInfo(spName1, affectedCount);
        using (OrderCommentRepository ocr = 
            new OrderCommentRepository(DbDataContext))
        {
            foreach (var comment in model.OrderComments)
            {
                List<ResultInfo> ri = new List<ResultInfo>();
                ocr.Create(comment, null, ri);
                resultInfo.ResultInfos.Add(ri);
            }
        }
        result.Add(resultInfo);
        DbDataContext.EndTransaction();
        return model;
    }
    catch
    {
        DbDataContext.EndTransaction(EndTransactioMode.Rollback);
    }
}

ResultInfo can allow applications to construct detailed messages about an operation. It enables data level trace-ability, answering the questions: What went in? What came out? This helps a lot specially when investigating issues that may be caused by data. This helps a lot when you need to build messages without necessarily throwing or bubbling up exceptions. This helps a lot in enabling different aspects and parts of your application to "communicate" and "exchange" data with each other.

Get started with using ResultInfo and Mendz.Data.Repository(.Async) now by downloading/installing Mendz.Data from NuGet.

Comments