You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I have a scenario where we get an event from an external system, this event is mapped and written to a marten event store for auditing.
I have enabled the unique key index on the ID column and would like to manually set the ID on my event records. I think from the docs it just asks to set an property such as Guid Id however, this does not appear to work. Demo app below. Any support appreciated.
usingSystem.Text.Json;usingSystem.Text.Json.Serialization;usingJasperFx.Core;usingMarten;usingMarten.Events;usingMarten.Services;usingMartenIdDemo.Events;usingWeasel.Core;varbuilder=WebApplication.CreateBuilder(args);builder.Services.AddMarten(
martenOptions =>{varconnectionString=builder.Configuration.GetConnectionString("DefaultConnection")??thrownewInvalidOperationException("Please provide a connection string to Postgres via ConnectionStrings:DefaultConnection");martenOptions.Connection(connectionString);martenOptions.AutoCreateSchemaObjects=AutoCreate.CreateOrUpdate;martenOptions.Events.EnableUniqueIndexOnEventId=true;martenOptions.Events.StreamIdentity=StreamIdentity.AsString;martenOptions.OpenTelemetry.TrackEventCounters();martenOptions.OpenTelemetry.TrackConnections=TrackLevel.Normal;martenOptions.UseSystemTextJsonForSerialization(newJsonSerializerOptions{PropertyNamingPolicy=JsonNamingPolicy.CamelCase,PropertyNameCaseInsensitive=true,Converters={newJsonStringEnumConverter()}});});varapp=builder.Build();vardocStore=app.Services.GetRequiredService<IDocumentStore>();awaitdocStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync();app.MapGet("/",async(IDocumentStoredocumentStore)=>{varid=Guid.NewGuid();varevt=newUserEvents.SignedUp(id,Guid.NewGuid().ToString());awaitusing(varsession=documentStore.LightweightSession()){session.Events.Append(evt.UserId,evt);awaitsession.SaveChangesAsync();}awaitusing(varsession=documentStore.LightweightSession()){varreturnedEvt=awaitsession.Events.QueryAllRawEvents().Where(x =>x.Id==id).ToListAsync();returnResults.Ok(returnedEvt);}});app.Run();
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I have a scenario where we get an event from an external system, this event is mapped and written to a marten event store for auditing.
I have enabled the unique key index on the ID column and would like to manually set the ID on my event records. I think from the docs it just asks to set an property such as
Guid Id
however, this does not appear to work. Demo app below. Any support appreciated.https://github.com/mumby0168/marten-id-demo
for ease of viewing here is the code snippet:
Beta Was this translation helpful? Give feedback.
All reactions