【发布时间】:2019-01-24 23:15:29
【问题描述】:
我有 2 个实体学生和课程如下。
public class Student
{
[Key]
public int Student_Id{ get; set; }
[StringLength(100)]
public string FirstName { get; set; }
[StringLength(100)]
public string LastName { get; set; }
[StringLength(1)]
public string Gender { get; set; }
public ICollection<Course> courses{ get; set; }
}
public class Courses
{
[Key]
public int Course_Id{ get; set; }
public int Student_Id{ get; set; }
[StringLength(100)]
public string CourseName{ get; set; }
[StringLength(10)]
public string Duration { get; set; }
}
以下 $expand 正在按预期工作。
http://localhost:61565/Odata/Student?$select=Student_Id,FirstName &$expand=Courses($select=Course_Id,CourseName)
无论如何我可以先 $expand 子实体“Courses”然后再扩展父“Student”吗 即使我添加以下代码
public ICollection<Student> Students{ get; set; }
到课程。当我使用 $expand 选项时,它会抛出错误。
有什么方法可以在父实体集和子实体集上双向设置导航属性或任何其他方式来处理它?
【问题讨论】:
标签: c# asp.net-mvc asp.net-web-api odata