여기에서 masstransit 샘플을 가지고 놀았습니다. https://github.com/MassTransit/Sample-ShoppingWeb masstransit의 최신 버전 (3.3.5)으로 업데이트되었지만 모든 것이 잘 작동합니다.Masstransit sagas 및 Entity Framework 리포지토리 모델 변경
내 ShoppingCart에 ShoppingCartItems를 추가하여 모델 및이 매핑에 추가했습니다.
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; }
}
이것은 시작에 실행 :
이SagaDbContextFactory sagaDbContextFactory =
() => new SagaDbContext<ShoppingCart, ShoppingCartMap>(SagaDbContextFactoryProvider.ConnectionString);
_repository = new Lazy<ISagaRepository<ShoppingCart>>(
() => new EntityFrameworkSagaRepository<ShoppingCart>(sagaDbContextFactory));
내가 얻을 문제는 모델이 변경되었습니다라는 오류 메시지입니다. 내가 데이터베이스를 드롭하고 처음부터 솔루션을 실행하면 작동하지만 나는 내 사가 클래스에서 변경해야 할 때마다 내 전체 DB를 드롭 싶지 않아.
내 계획은 무용담을 통해 내 쇼핑 카트를 구축하는 것이며 완료된 상태에 도달하면 무용담 컨텍스트 (ShoppingCart)를 사용하여 실제 주문을 만들고 유지합니다. 어쩌면 나는이 모든 잘못을 겪고 서사의 전체 개념을 이해하지 못했을 까? 그렇다면 복합 객체 그래프를 가진 무용담에 대해 어떻게 생각하나요?