Asp.net mvc ASP.NET MVC查找未决费用

Asp.net mvc ASP.NET MVC查找未决费用,asp.net-mvc,entity-framework,asp.net-mvc-4,domain-driven-design,Asp.net Mvc,Entity Framework,Asp.net Mvc 4,Domain Driven Design,我正在学习使用实体框架的ASP.NETMVC4(首先是数据库),遇到了一个我无法解决的问题 我有以下表格: 学生:存储学生信息 课程:存储在学院中运行的课程 StudentCourse:存储哪个学生选择了什么课程 费用:存储学生提交的与StudentCourse对应的费用 现在,我不想显示课程名称、课程费用、提交的总费用以及学生的待定费用 我在项目中使用实体框架,并尝试执行如下查询: var feeslist = entities.Fees .Where(m => m.

我正在学习使用实体框架的ASP.NETMVC4(首先是数据库),遇到了一个我无法解决的问题

我有以下表格:

  • 学生:存储学生信息
  • 课程:存储在学院中运行的课程
  • StudentCourse:存储哪个学生选择了什么课程
  • 费用:存储学生提交的与StudentCourse对应的费用
现在,我不想显示课程名称、课程费用、提交的总费用以及学生的待定费用 我在项目中使用实体框架,并尝试执行如下查询:

var feeslist = entities.Fees
        .Where(m => m.StudentCourse.status=="pending")
        .GroupBy(m => m.StudentCourse.id)
        .Select(m => new { StudentCourseId = m.Key, SumOfFees = m.Sum(v => v.fees) });
我想获取课程对象而不是StudentCourseId,以便显示课程、课程费用以及学生提交的总费用

在这种情况下,我列出了所有四个类的内容:

学生
如果你想最终得到课程对象,你应该用
var courseList=entities.Courses.Where(…)
等东西开始你的查询,然后反向工作。感谢Elliot的快速回复,但是写什么。选择()来获得课程对象?从域驱动的设计角度来看,这是完全错误的。这些数据结构源自关系范式。
public partial class Student
{
    public Student()
    {
        this.Leaves = new HashSet<Leave>();
        this.StudentCourses = new HashSet<StudentCourse>();
    }

    public int id { get; set; }
    public string first_name { get; set; }
    public string middle_name { get; set; }
    public string last_name { get; set; }
    public string password { get; set; }
    public string email { get; set; }
    public string gender { get; set; }
    public string facebook { get; set; }
    public string contact_number { get; set; }
    public string address { get; set; }
    public string admin { get; set; }
    public string college { get; set; }
    public string status { get; set; }
    public System.DateTime createdat { get; set; }
    public System.DateTime updatedat { get; set; }
    public string descripton { get; set; }

    public virtual ICollection<Leave> Leaves { get; set; }
    public virtual ICollection<StudentCourse> StudentCourses { get; set; }
}
public partial class Course
{
    public Course()
    {
        this.CourseContents = new HashSet<CourseContent>();
        this.StudentCourses = new HashSet<StudentCourse>();
    }

    public int id { get; set; }
    public string course_name { get; set; }
    public int course_fees { get; set; }
    public int duration { get; set; }
    public string admin { get; set; }
    public string status { get; set; }
    public System.DateTime createdat { get; set; }
    public System.DateTime updatedat { get; set; }

    public virtual ICollection<CourseContent> CourseContents { get; set; }
    public virtual ICollection<StudentCourse> StudentCourses { get; set; }
}
public partial class StudentCourse
{
    public StudentCourse()
    {
        this.Fees1 = new HashSet<Fee>();
        this.Issues = new HashSet<Issue>();
    }

    public int id { get; set; }
    public int student_id { get; set; }
    public int course_id { get; set; }
    public int fees { get; set; }
    public System.DateTime join_date { get; set; }
    public string admin { get; set; }
    public System.DateTime createdat { get; set; }
    public System.DateTime updatedat { get; set; }
    public string status { get; set; }

    public virtual Course Course { get; set; }
    public virtual ICollection<Fee> Fees1 { get; set; }
    public virtual ICollection<Issue> Issues { get; set; }
    public virtual Student Student { get; set; }
}
public partial class Fee
{
    public int id { get; set; }
    public int student_course_id { get; set; }
    public int fees { get; set; }
    public string admin { get; set; }
    public System.DateTime createdat { get; set; }
    public System.DateTime updatedat { get; set; }

    public virtual StudentCourse StudentCourse { get; set; }
}
var feeslist = entities.Fees
        .Where(m => m.StudentCourse.status=="pending")
        .GroupBy(m => m.StudentCourse.Course)
        .Select(m => new { Course = m.Key, SumOfFees = m.Sum(v => v.fees) });