CQRSalad.EventStore.MongoDB.MongoSnapshotSerializer.Deserialize C# (CSharp) Method

Deserialize() public method

public Deserialize ( BsonDocument bsonDocument ) : AggregateSnapshot
bsonDocument BsonDocument
return CQRSalad.EventSourcing.AggregateSnapshot
        public AggregateSnapshot Deserialize(BsonDocument bsonDocument)
        {
            return new AggregateSnapshot()
            {
                AggregateId = bsonDocument[AggregateIdElement].AsString,
                AggregateType = bsonDocument[AggregateTypeElement].AsType(),
                Version = bsonDocument[VersionElement].AsInt32,
                Timestamp = bsonDocument[TimestampElement].ToUniversalTime(),
                State = _dataSerializer.Deserialize(bsonDocument[StateElement].AsBsonDocument, bsonDocument[StateTypeElement].AsType())
            };
        }
    }

Usage Example

Example #1
0
        public async Task <AggregateSnapshot> LoadSnapshot(string aggregateId)
        {
            var snapshot = await GetCollection().Find(_snapshotSerializer.GetIdFilter(aggregateId)).FirstOrDefaultAsync();

            return(snapshot != null?_snapshotSerializer.Deserialize(snapshot) : null);
        }