0

在我的数据库中,我有 4 个具有如下关系的表:

检查 --> Correspondence --> CorrespondenceTo, User

现在,当InspectionID等于某物时,我想得到Subject, CorrespondenceType, SentDatefrom Correspondence, DisplayNamefrom User, FirstName, LastNamefrom CorrespondenceTo。所以我写这样的代码:

var result = from i in context.Inspections
        join correspondence in context.Correspondences 
            on i.Id equals correspondence.InspectionId
        join correspondenceTo in context.CorrespondenceToes 
            on correspondence.Id equals correspondenceTo.CorrespondenceId
        join user in context.Users 
            on correspondence.SenderUserId equals user.Id

        where i.Id == inspectionID
        select new
        {
            Subject = correspondence.Subject,
            CorrespondenceType = correspondence.CorrespondenceType,
            SentDate = correspondence.SentDate,
            Sender = user.DisplayName,
            Receiver = new
            {
               correspondenceTo.FirstName,
               correspondenceTo.LastName
            }
        };
return Json(result);

我的代码有什么问题?如何在 Visual Studio 2012 中查看结果?此外,我想离开加入上面的所有表格。我应该怎么办?如果我想使用Include而不是Join,该怎么做?

4

0 回答 0