获取表格ID的数值

huangapple go评论83阅读模式
英文:

Getting Value for table_id

问题

我有2张表 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; }
}

现在我想获取所有待付款的分期付款,
但我还想包括来自分期付款表的 SaleMaster ID,以便我可以导航回去。

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

现在我想从这个待付款分期付款列表中获取 SaleMaster
英文:

I have 2 tables SaleMaster

public class SaleMaster
{
    public int Id { get; set; }
    public List&lt;Installments&gt; 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&lt;Installments&gt; instalment = con.DbSetInstallments
    .Where(x =&gt; x.Month &lt; d &amp;&amp; x.IsPaid == false)
    .ToList();

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

答案1

得分: 1

你可以在 Installments 中为 SaleMaster 添加一个关联属性:

public class Installments
{
    // ...
    public int SaleMasterId { get; set; }
    public virtual SaleMaster SaleMaster { get; set; }
}

这样你就可以轻松访问 SaleMaster 的 Id

英文:

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.

huangapple
  • 本文由 发表于 2023年1月9日 16:37:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75054791.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定