Hi I have an entity as below
public class SalaryTransactionAudit
{
public long SalaryTransactionAuditId { get; set; }
public Guid TransactionBatchId { get; set; }
public DateTime UploadedDate { get; set; }
public string UploadedBy { get; set; }
public long SalaryTransactionStatusId { get; set; }
}
The above entity has primary key on SalaryTransactionAuditId and Alternate Key on TransactionBatchId as below
public class SalaryTransactionAuditConfiguration : IEntityTypeConfiguration<SalaryTransactionAudit>
{
public void Configure(EntityTypeBuilder<SalaryTransactionAudit> builder)
{
builder.ToTable("SalaryTransactionAudit");
builder.HasKey(e => e.SalaryTransactionAuditId);
builder.HasAlternateKey(e => e.TransactionBatchId);
}
}
And I also have this entity
public class SalaryTransaction
{
public long SalaryTransactionId { get; set; }
public Guid TransactionBatchId { get; set; }
public long EmployeeId { get; set; }
public int AnnualSalary { get; set; }
public int SuperRate { get; set; }
public int PaymentPeriodYear { get; set; }
public int PaymentPeriodMonth { get; set; }
public Employee Employee { get; set; }
}
How do I configure (using fluent API) for FK Constraint on TransactionBatchId something like below
public class SalaryTransactionConfiguration : IEntityTypeConfiguration<SalaryTransaction>
{
public void Configure(EntityTypeBuilder<SalaryTransaction> builder)
{
builder.ToTable("SalaryTransaction");
builder.HasKey(e => e.SalaryTransactionId);
builder.HasForeignKey(e => e.TransactionBatchId );
}
}