I've been playing around with the masstransit sample from here https://github.com/MassTransit/Sample-ShoppingWeb Allthough i have updated to the latest version(3.3.5) of masstransit and everything works fine.
I want to add ShoppingCartItems to my ShoppingCart so i added it to the model and the mapping like this.
public class ShoppingCartMap :
SagaClassMapping<ShoppingCart>
{
public ShoppingCartMap()
{
Property(x => x.CurrentState)
.HasMaxLength(64);
Property(x => x.Created);
Property(x => x.Updated);
Property(x => x.UserName)
.HasMaxLength(256);
Property(x => x.ExpirationId);
Property(x => x.OrderId);
HasMany(c => c.ShoppingCartItems);
}
}
public class ShoppingCart :
SagaStateMachineInstance
{
public string CurrentState { get; set; }
public string UserName { get; set; }
public DateTime Created { get; set; }
public DateTime Updated { get; set; }
/// <summary>
/// The expiration tag for the shopping cart, which is scheduled whenever
/// the cart is updated
/// </summary>
public Guid? ExpirationId { get; set; }
public Guid? OrderId { get; set; }
public Guid CorrelationId { get; set; }
public virtual List<ShoppingCartItem> ShoppingCartItems { get; set; } = new List<ShoppingCartItem>();
}
public class ShoppingCartItem
{
public Guid? Id { get; set; }
public string Name { get; set; }
public Guid? OrderId { get; set; }
}
This is run at startup:
SagaDbContextFactory sagaDbContextFactory =
() => new SagaDbContext<ShoppingCart, ShoppingCartMap>(SagaDbContextFactoryProvider.ConnectionString);
_repository = new Lazy<ISagaRepository<ShoppingCart>>(
() => new EntityFrameworkSagaRepository<ShoppingCart>(sagaDbContextFactory));
The problem i get is an error message saying the model has changed. If i drop the database and run the solution from scratch it works but i dont want to drop my entire DB every time i need to make a change in my saga class.
My plan is to build my ShoppingCart through the saga and when i reach my finished state i will use the saga context(ShoppingCart) to create and persist real orders. Maybe i am going by this all wrong and have missunderstood the whole concept of sagas? If so how would one go about sagas that have complex object graphs?