1

我有三个抽象支付类。

public class CardPayment : Payment
{
    public CardPayment(Guid distributeId, Guid invoiceId, int userId, decimal amount, DateTime dateTime, long serialNumbner, long terminalNumber, long referenceNumber, DateTime bankDateTime) : base(distributeId, invoiceId, userId, amount, dateTime)
    public long SerialNumber { get;private set; }
    public long TerminalNumber { get; private set; }
    public long ReferenceNumber { get; set; }
    public DateTime BankDateTime { get; set; }
}

public  class Payment: EntityBase<Guid>
{
    public Guid DistributeId { get; private set; }
    public Guid InvoiceId { get; private set; }
    public int UserId { get; private set; }
    public decimal Amount { get; set; }
    public DateTime DateTime { get; set; }
    public  PaymentType Type { get; set; }
}

public class CashPayment : Payment
{
    public CashPayment(Guid distributeId, Guid invoiceId, int userId, decimal amount, DateTime dateTime) : base(distributeId, invoiceId, userId, amount,dateTime)
    {
    }
}


public class ChequePayment : Payment
{

    public string SerialNumber { get; private set; }
    public int BankId { get; private set; }
    public string BankBranchName { get; set; }
    public string NationalCode { get; set; }
    public string BankBranchCode { get; set; }
    public DateTime DueDate { get; set; }
    public string BankAccountNumber { get; set; }
    public string SayddiNumber { get; set; }

    
}

这些如上所示。

我使用 ef-core。我想使用 TPH 来持久化。

 public class Invoice : EntityBase<Guid>, IAggregateRoot<Invoice>
{
    protected List<Payment> _payments = new List<Payment>();
    public IReadOnlyCollection<Payment> Payments => _payments.AsReadOnly();
}

另一方面,我使用基类来映射这样的聚合根。

public abstract class EntityMappingBase<TEntity> : IEntityTypeConfiguration<TEntity>
    where TEntity : class,IEntityBase, IAggregateRoot<TEntity>
{

    public abstract void Configure(EntityTypeBuilder<TEntity> builder);
}

}

   public class InvoiceMapping : EntityMappingBase<Invoice>
    {
        public override void Configure(EntityTypeBuilder<Invoice> builder)
        {
            Initial(builder);


            builder.OwnsMany(a => a.Payments, map =>
            {
                map.Property(i => i.Id)
               .ValueGeneratedNever();
                map.HasKey(i => i.Id);

                map.WithOwner().HasForeignKey("InvoiceId");

                map.UsePropertyAccessMode(PropertyAccessMode.Field);


                ToTable(map);
            });

        }
    }

但我没有将这些类映射到发票类。

4

0 回答 0