You can use the client API to write one or more events to a stream atomically. You do this by appending the events to the stream in one operation, or by starting a transaction on the stream, writing events in one or more operations in that transaction, and then committing the transaction.
You can make an optimistic concurrency check during the write by specifying the version at which the stream is expected to be. Identical write operations are idempotent if the optimistic concurrency check is not disabled. You can find more information on optimistic concurrency and idempotence here.
Task<WriteResult> AppendToStreamAsync(string stream, long expectedVersion, IEnumerable<EventData> events)
Task<WriteResult> AppendToStreamAsync(string stream, long expectedVersion, params EventData events)
Task<EventStoreTransaction> StartTransactionAsync(string stream, long expectedVersion)
EventStoreTransaction ContinueTransaction(long transactionId)
Task WriteAsync(IEnumerable<EventData> events)
Task WriteAsync(params EventData events)
The writing methods all use a type named
EventData to represent an event to be stored. Instances of
EventData are immutable.
Event Store does not have any built-in serialisation, so the body and metadata for each event are represented in
EventData as a
The members on
||A unique identifier representing this event. This is used internally for idempotency if you write the same event twice you should use the same identifier both times.|
||The name of the event type. This can be used later for pattern matching in projections, so should be a “friendly” name rather than a CLR type name, for example.</code>|
||If the data and metadata fields are serialized as JSON, this should be set to true. Setting this to `true` will cause the projections framework to attempt to deserialize the data and metadata later.|
||The serialized data representing the event to be stored.|
||The serialized data representing metadata about the event to be stored.|
AppendToStreamAsync method writes events atomically to the end of a stream, working in an asynchronous manner.
The parameters are:
||The name of the stream to which to append.|
||The version at which we currently expect the stream to be in order that an optimistic concurrency check can be performed. This should either be a positive integer, or one of the constants `ExpectedVersion.NoStream`, `ExpectedVersion.EmptyStream`, or to disable the check, `ExpectedVersion.Any`. See here for a broader discussion of this.|
||The events to append. There is also an overload of each method which takes the events as a `params` array.|