LINQ 检索多对一关系数据库

LINQ Retrieve many to one relationship database

我目前有以下 LINQ 代码在工作,return每个引号一行。我需要将其修改为 return 一个额外的 table,每个引号可能有很多记录,我不确定如何添加这段代码,因为我还在学习。

    var query = DbContext.QuoteInformation
                .Include("Customer")
                .Include("Priority")
                .Include("Status")
                .OrderBy(q => q.RFQ);

    totalRecords = query.Count();

    return query.ToList();

我需要包含在这个查询中的 table 有这些列 -

public class QuoteTransaction
{
    [Key]
    public Guid Id { get; set; }
    public Guid QuoteInformationId { get; set; }
    public Guid DepartmentId { get; set; }
    public Guid StatusId { get; set; }
    public bool Checked { get; set; }
    public string Comments { get; set; }
    public string UserId { get; set; }

    public QuoteInformation QuoteInformation { get; set; }
    public Department Department { get; set; }
    public Status Status { get; set; }
    public ApplicationUser User { get; set; }

    public QuoteTransaction()
    {
        Id = SequentialGuid.Create(SequentialGuidType.SequentialAtEnd);
    }
}

您需要添加一个属性

public virtual List<QuoteTransaction> QuoteTransactions{ get; set; }

进入class QuoteInformation 以获取交易列表

然后使用 .Include("QuoteTransactions")

更改您的 LINQ

您还可以通过在 LINQ 中添加以下代码来包含 return 导航 属性 异常

.Include(r=>r.QuoteTransactions)