Set foreign keys of same class in Entity Framework in ASP.Net

on Aug 13, 2020 11:30 PM

I want to achieve relationship like ContractFatherId to IDContract of this same table.

Previously we are using sql constraints.

CONSTRAINT [FK_tabContract_tabContractFather] FOREIGN KEY ([ContractFatherId]) REFERENCES [dbo].[tabContract] ([IDContract])

I have an Entity Called Contract

public class Contract 
    public int IDContract { get; set; }
    public string Code { get; set; }
    public string Description { get; set; }
    public int ContractFatherId { get; set; }
    public ContractTypeGroup ContractTypeGroup { get; set; }
    public int ContractTypeId { get; set; }
    public bool AutoGenerated { get; set; } = false;
    public BlobStorage Image { get; set; }
    public int? ImageId { get; set; }


Download FREE API for Word, Excel and PDF in ASP.Net: Download