How to map single database column to 2 different entity properties in Entity Framework Core 6

57 Views Asked by At

In EF Core 3.1, I can map 1 database column to 2 different entity properties but I am not able to do the same in version 6.0.

I am getting this error:

'ClaimAmountTransaction.BankReferenceNumber' and 'ClaimAmountTransaction.PaymentTransactionReferenceNumber' are both mapped to column 'BNK_REF_NBR' in 'Claim.CLAIM_AMOUNT_TRANSACTION', but the properties are contained within the same hierarchy. All properties on an entity type must be mapped to unique different columns.

Context:

entity.Property(e => e.BnkRefNbr)
      .HasMaxLength(16)
      .HasColumnName("BNK_REF_NBR").IsRequired() ;
entity.Property(e => e.PaymentTrnsRefNbr)
      .HasColumnName("BNK_REF_NBR");
public string? BnkRefNbr { get; set; }
public string? PaymentTrnsRefNbr  { get; set; }

I tried some ways, but getting the same error or the error is

Invalid column name "PaymentTrnsRefNbr".

Please suggest a way to resolve this.

0

There are 0 best solutions below