Search code examples
masstransit

Preferred way of returning multiple MassTransit Saga states by single request?


I am using SQL Server with Entity Framework to persist Saga states, I am also using CQRS pattern throughout the project.

I have the need to read and return a subset (based on some rules or conditions, e.g. Saga state equals failed) of all persisted Saga states. I am wondering what should be the preferred way of doing this?

Should I just write Dapper query directly against the table where Saga states are persisted or should I mirror Saga state table into a separate read-only table and then write queries against it?

Reading 1 saga state by Id is pretty trivial (for example, as shown here https://stackoverflow.com/a/71654974/5132661) but I can't find examples if the need is to get and read N saga states.


Solution

  • If you're using Entity Framework, you have the DbContext. You can use that DbContext to query the saga repository using a Where statement, the same as you could any entity using EF.