EF:如何为具有GradeId = 1的“学生”获取“成绩”实体

时间:2019-03-02 08:08:24

标签: c# entity-framework

我在数据库结构下面有数据,

enter image description here

下面是entitydbContext类,

public class SchoolContext : DbContext
{
    public DbSet<Grade> Grades { get; set; }
    public DbSet<Student> Students { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlServer(@"Server=(localdb)\MSSQLLocalDB;Database=SchoolDB;Trusted_Connection=True;");
    }
}

public class Grade
{
    public int Id { get; set; }
    public string GradeName { get; set; }

    public virtual ICollection<Student> Students { get; set; } = new HashSet<Student>();
}

public class Student
{
    public int Id { get; set; }
    public string StudentName { get; set; }
}

现在,我正在尝试获取Grade的{​​{1}}实体,其GradeId = 1。如何通过GradeId?

Student

2 个答案:

答案 0 :(得分:2)

似乎您实际上是在尝试获得ID等于1的成绩并预加载相关数据。因此,您可以尝试以下方法:

CFSocketConnectToAddress(self.socket, sin_cfd, -1)

答案 1 :(得分:0)

一种可能的解决方案:

<meta name="viewport" content="width=device-width, initial-scale=1.0">