【发布时间】:2016-10-11 00:04:58
【问题描述】:
我有一个项目,它是一个 Asp.net Web API。
这是我的控制器:
public IEnumerable<Students> GetBasicInfo()
{
var students = db.Students.Include("Courses").Select(p => new Students
{
student_id = p.student_id,
student_number = p.student_number,
first_name = p.first_name,
middle_name = p.middle_name,
last_name = p.last_name,
display_name = p.display_name,
address = p.address,
birthdate = p.birthdate,
contact_number = p.contact_number,
email = p.email,
student_img = p.student_img,
courses = p.courses.Select(a => new Courses
{
course_id = a.course_id,
name = a.name
})
}).ToList();
return students;
}
这是我的模型
Students.cs
public partial class Students
{
public System.Guid student_id { get; set; }
public string student_number { get; set; }
public string first_name { get; set; }
public string middle_name { get; set; }
public string last_name { get; set; }
public string display_name { get; set; }
public string address { get; set; }
public System.DateTime birthdate { get; set; }
public Nullable<int> course_id { get; set; }
public string contact_number { get; set; }
public string email { get; set; }
public byte[] student_img { get; set; }
public IEnumerable<Courses> courses { get; set; }
}
这是 Courses.cs
public partial class Courses
{
public int course_id { get; set; }
public string name { get; set; }
}
但是它返回一个错误,上面写着
'实体或复杂类型'StudentModel.Studentss'不能是 在 LINQ to Entities 查询中构造。'。
知道为什么吗?
【问题讨论】:
标签: c# asp.net entity-framework linq asp.net-web-api