I'm working on a generic batch component (Publish message in Saga where type is known only runtime) heavily inspired by Chris Pattersons sample https://github.com/MassTransit/Sample-Batch. However there seems to be an issue with the sample, the navigation properties on BatchState and BatchJobState are not working.
In the BatchStateMachine when a BatchJobDone event is fired i need to detect if it's the last BatchJob in order to fire a new event.
public class BatchState :
SagaStateMachineInstance
{
...
// Navigation Properties
public List<BatchJobState> Jobs { get; set; } = new List<BatchJobState>();
public Guid CorrelationId { get; set; }
}
public class BatchJobState :
SagaStateMachineInstance
{
...
// Navigation Properties
public BatchState Batch { get; set; }
public Guid CorrelationId { get; set; }
}
The Batch property on BatchJobState is always null and the Jobs property on BatchState is always Count = 0
They're configured like this:
class BatchStateEntityConfiguration :
IEntityTypeConfiguration<BatchState>
{
public void Configure(EntityTypeBuilder<BatchState> builder)
{
builder.HasKey(c => c.CorrelationId);
builder.Property(c => c.CorrelationId)
.ValueGeneratedNever()
.HasColumnName("BatchId");
builder.Property(c => c.CurrentState).IsRequired();
builder.Property(c => c.Action)
.HasConversion(new EnumToStringConverter<BatchAction>());
builder.Property(c => c.UnprocessedOrderIds)
.HasConversion(new JsonValueConverter<Stack<Guid>>())
.Metadata.SetValueComparer(new JsonValueComparer<Stack<Guid>>());
builder.Property(c => c.ProcessingOrderIds)
.HasConversion(new JsonValueConverter<Dictionary<Guid, Guid>>())
.Metadata.SetValueComparer(new JsonValueComparer<Dictionary<Guid, Guid>>());
}
}
class JobStateEntityConfiguration :
IEntityTypeConfiguration<BatchJobState>
{
public void Configure(EntityTypeBuilder<BatchJobState> builder)
{
builder.HasKey(c => c.CorrelationId);
builder.Property(c => c.CorrelationId)
.ValueGeneratedNever()
.HasColumnName("BatchJobId");
builder.Property(c => c.CurrentState).IsRequired();
builder.Property(c => c.Action)
.HasConversion(new EnumToStringConverter<BatchAction>());
}
}