Home > Net >  Getting Value for table_id
Getting Value for table_id

Time:01-09

I have 2 tables SaleMaster

public class SaleMaster
{
    public int Id { get; set; }
    public List<Installments> Installments { get; set; }
}
public class Installments
{
    public int Id { get; set; }
    public decimal Amount { get; set; }
    public DateTime Month { get; set; }
    public bool IsPaid { get; set; }
}

Now I want to get the all the Installments with pending due dates, but I also want to include the SaleMaster ID from Installment table so I can navigate back.

List<Installments> instalment = con.DbSetInstallments
    .Where(x => x.Month < d && x.IsPaid == false)
    .ToList();

Now I want to take SaleMaster from this list of which Installments are due.

CodePudding user response:

You can add a relational property to SaleMaster in Installments:

public class Installments
{
    public int Id { get; set; }
    public decimal Amount { get; set; }
    public DateTime Month { get; set; }
    public bool IsPaid { get; set; }

    public int SaleMasterId { get; set; }
    public virtual SaleMaster SaleMaster { get; set; }
}

This way you have easy access to the SaleMaster's Id.

  • Related