Take the 2-minute tour ×

I have a saga that has 3 states -

    public static State Initial { get; set; }
    public static State ReceivingRows { get; set; }
    public static State Completed { get; set; }

It transitions from Initial to ReceivingRows when it gets a BofMessage (where Bof = Beginning of file). After the BofMessage, it receives a large number of RowMessages where each describes a row in a flat file. Once all RowMessages are sent, an EofMessage is sent and the state changes to Completed. Observe -

static void DefineSagaBehavior()
        .Then((saga, message) => saga.BeginFile(message))

    During(ReceivingRows, When(ReceivedRow)
        .Then((saga, message) => saga.AddRow(message)));

    During(ReceivingRows, When(ReceivedRowError)
        .Then((saga, message) => saga.RowError(message)));

    During(ReceivingRows, When(ReceivedEof)
        .Then((saga, message) => saga.EndFile(message))

public override void OnAddRow(ParcelRowMessage message)
    // ensure isCauvReturned is "Y"
    var fields = message.Value;
    var isCauvReturned = fields[33] == "Y";
    if (!isCauvReturned)

    // add row with just parcel number
    var parcelNumber = fields[1];
    var row = parcelNumber;

This works except that it has n-squared performance. Investigating with NHProf reveals that each row add causes the entire list of rows to be:

A) selected from the database

B) deleted from the database

C) reinserted into the database.

This seems like very bad behavior to me. All that is needed to add a row is to… well, add a single row to the database! The add operation is literally the only thing I’m doing with the row list. This does not scale when we have 10,000's of items in the list.

Does anyone know how to give this saga more sane performance behavior?

BTW - here's how the IList is mapped if you need it -

        HasMany(x => x.Rows)

Thank you!

share|improve this question
add comment

1 Answer

Please have a look at


share|improve this answer
I researched this, but I am afraid it doesn't give me enough specifics to go on. Could you give a more specific answer? –  Bryan Edds May 23 '12 at 12:43
add comment

Your Answer


