Code Monkey home page Code Monkey logo

Comments (5)

gautema avatar gautema commented on August 20, 2024 2

Can you try to just add .Where(x => x.Version > fromVersion) to the bottom of your method?

from cqrslite.

andrewmurray avatar andrewmurray commented on August 20, 2024 1

OK, so IEventStore.Get, in the sample, only loads those events that haven't already been loaded?

My implementation of IEventStore.Get just now reads all events related to the stream for that aggregate:

        public async Task<IEnumerable<IEvent>> Get(Guid aggregateId, int fromVersion)
        {
            var streamEvents = new List<ResolvedEvent>();

            StreamEventsSlice currentSlice;
            var nextSliceStart = (long)StreamPosition.Start;
            do
            {
                currentSlice = await _connection.ReadStreamEventsForwardAsync(
                    StreamName($"booking-{aggregateId}"), nextSliceStart, 200, false);

                nextSliceStart = currentSlice.NextEventNumber;

                streamEvents.AddRange(currentSlice.Events);
            } while (!currentSlice.IsEndOfStream);

            return streamEvents.Select(e => (BaseEvent)RebuildEvent(e));
        }

This is pretty much just a lift and drop from the Event Store documentation (http://docs.geteventstore.com/dotnet-api/4.0.0/reading-events/).

The input for fromVersion will be 0 given that that's the expected version.

from cqrslite.

andrewmurray avatar andrewmurray commented on August 20, 2024 1

Yes I can! That fixes it.

Ok, understanding adjusted I think. IEventStore.Get MUST only return those events that have a version greater than that passed in. I was going on the assumption that I could ignore the fromVersion for the time being assuming it was just a convenience provided to improve performance, but it's actually linked to the successful saving of the new events.

Thanks for your help and the prompt replies!

from cqrslite.

gautema avatar gautema commented on August 20, 2024

What does _eventStore.Get return in the method you are asking for and what is the input? The implementation in the sample is like this events?.Where(x => x.Version > fromVersion) ?? new List<IEvent>(), so it only returns the events saved after the current version.

from cqrslite.

gautema avatar gautema commented on August 20, 2024

Yes, that's the way it is now. It could possibly be moved into the repository as well, but where put there for performance reasons, so the eventstore would not necessarily need to load all events every time.

from cqrslite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.