我有一个支付系统,如下所示.付款可以通过多个礼券进行.礼品券与购买一起发行.客户可以使用此礼品券以备将来购买.
当通过礼品券进行付款时,GiftCoupon表中的UsedForPaymentID列需要使用该PaymentID(对于礼品券ID)进行更新.
GiftCouponID已在数据库中提供.当客户生产礼品券时,它上面印有GiftCouponID.运营商需要将此CouponID输入系统以进行付款.
对于MakePayment()操作,它需要两个存储库.
码
//使用GiftCouponRepository检索相应的GiftCoupon对象.
这涉及为一个事务使用两个存储库.这是一个好习惯吗?如果没有,我们如何改变设计来克服这个问题呢?
参考:在DDD中,Aggregate应代表事务边界.需要涉及多个聚合的交易通常表明应该改进模型,或者应该审查交易要求,或者两者兼而有之.CQRS对我的域名是否正确?

C#代码
public RepositoryLayer.ILijosPaymentRepository repository { get; set; }
public void MakePayment(int giftCouponID)
{
DBML_Project.Payment paymentEntity = new DBML_Project.Payment();
paymentEntity.PaymentID = 1;
DBML_Project.GiftCoupon giftCouponObj;
//Use GiftCouponRepository to retrieve the corresponding GiftCoupon object.
paymentEntity.GiftCouponPayments = new System.Data.Linq.EntitySet<DBML_Project.GiftCoupon>();
paymentEntity.GiftCouponPayments.Add(giftCouponObj);
repository.InsertEntity(paymentEntity);
repository.SubmitChanges();
}
Run Code Online (Sandbox Code Playgroud)