Order By Date LINQ查询中的时间中断



下面详细说明了我得到的错误学生班

public class Student () {
public int Id {get;set;}
public Student(int id IEnumerable<StudentOwner> owner) {
_owners = owners != null ? owners.ToList() : new List<StudentOwner>();
}
private List<StudentOwner> _owners;
}

StudentDetailsClass

public class StudentDetails () {
pubiic int Id {get; set;}
public DateTime UpdateDate { get; }
public string Comments { get; set; }
public int StudentRef {get; set; }
}

查询的违规代码的选择如下,如果您按s.ID订购它就可以工作

baseQuery = baseQuery.Where(
o => s.StudentDetails
.OrderByDescending(s => **s.UpdateDate**).First().StudentRef
== StudentSearchParams.StudentRef;

出现以下错误,但是如果您按Id排序,它可以工作,但不会产生所需的结果。有什么想法吗??

.OrderByDescending(s1 => s1.UpdateDate)' could not be translated. 
Additional information: Translation of member 'UpdateDate' on entity type 'StudentDetails' failed. 
This commonly occurs when the specified member is unmapped. Either rewrite the query in a form 
that can be translated, or switch to client evaluation explicitly by inserting a call to 
'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

错误信息告诉你

在实体类型'StudentDetails'上翻译成员'UpdateDate'失败。当指定的成员未映射时,通常会发生这种情况

你得到的是

public class StudentDetails
{
public DateTime UpdateDate { get; }
}

只获取属性(没有setter)。和EF Core约定

按照约定,所有带有getter和setter的公共属性都将包含在模型中。

换句话说,没有setter的属性被忽略(不包含,不映射)。

get;后面加上set;,问题就解决了。

最新更新