Implementing GetAll for a repository

Hi

Any suggestions on how to implement a GetAll repository method for a given aggregate type T?

Thank you.

Event Store is no read model! And even for a read model implementing GetAll is an anti-pattern. What about if you have 10 Mio instances of T?

Let me rephrase the question. How about an implementation of Take<T>(int count)? Are there primitives for supporting such a thing? Or is this a completely wrong direction to take..

Where is this Index you are Taking from? :wink:

if your streams look like this:

customer-[customerId]

then you can just read the stream $ce-customer

The Aggregate doesn’t exist, for all intents and purposes. It’s really an IEnumerable.

Effectively what you’re asking for is an IEnumerable<IEnumerable> and then Partition by Id. I think João has provided that answer.

Do you really want to query over projections from the event store?

You absolutely could implement a GetAll, but it would require a secondary index for you to know about all the stream names for aggregates of type T. As Joao says, you could do that by reading $ce-T.

However, the more important question is why you want this - generally you would not be querying via a repository, and commands would target a specific aggregate and thus stream.

Either way, a GetAll would be an unbounded result set in most systems, which would be a Bad Plan™.

James

I hope you can bear with me, I'm new to event sourcing. So how would you generally be querying? Via a read model as suggested earlier?

Generally yes for such queries.