以下詳細說明了我收到學生類的錯誤
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.
uj5u.com熱心網友回復:
錯誤資訊告訴你
物體型別“StudentDetails”上成員“UpdateDate”的翻譯失敗。這通常發生在指定成員未映射時
而你所擁有的是
public class StudentDetails
{
public DateTime UpdateDate { get; }
}
即只獲取屬性(沒有設定器)。并通過 EF Core 約定
按照慣例,所有帶有 getter 和 setter 的公共屬性都將包含在模型中。
換句話說,沒有設定器的屬性被忽略(不包括,未映射)。
追加set;之后get;,問題就會消失。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/328456.html
