-3

如何使用 Class 中的 Property,Project.Project_ID以便在 Class 中调用它R_Project _Status并在 View ASP.NET CORE C# 中显示?请用 MVC 解释示例

问题

在此处输入图像描述

4

1 回答 1

0

您应该将 EF 与 Linq 一起使用:我希望您已经成功地“搭建”了脚手架,猜测您已经拥有以下类:

public partial class Project
{
    public int ProjectId { get; set; }
    public int Source { get; set; }

    public virtual RSource SourceNavigation { get; set; }
}
public partial class RProjectStatus
{
    public int StatusType { get; set; }
    public int Source { get; set; }

    public virtual RSource SourceNavigation { get; set; }
}
public partial class RSource
{
    public RSource()
    {
        Project = new HashSet<Project>();
        RProjectStatus = new HashSet<RProjectStatus>();
    }

    public int Source { get; set; }

    public virtual ICollection<Project> Project { get; set; }
    public virtual ICollection<RProjectStatus> RProjectStatus { get; set; }
}

您现在要做的一切是(假设您已经将 _context 作为 DatabaseContext)

var ps = _context.RProjectStatus
                .Include(x => x.SourceNavigation)
                .ThenInclude(x => x.Project);
// now do any stuff you want with "ps" variable:
List<int> projectIdList = ps.FirstOrDefault()
            .SourceNavigation
            .Project
            .Select(x => x.ProjectId)
            .ToList();
于 2019-01-06T11:20:04.950 回答