1
我試圖找到這個答案。LINQ過濾一個數據庫列表與另一個數據庫列表
我正在使用LINQ並嘗試使用另一個列表過濾數據庫列表,以從成員已經是公民的國家/地區列表中刪除國家/地區。
var currentCitizenships = DbContext.Citizenships
.Where(c => c.MemberId == CurrentUser.MemberId)
.Include(c => c.Country)
.ToList();
var filtered = DbContext.Countries
.Where(c => !currentCitizenships.Any(current => current.Country.CountryId == c.CountryId));
我得到一個Not supported exception
以下消息:
Unable to create a constant value of type 'Project.EntityFramework.Models.Citizenship'. Only primitive types or enumeration types are supported in this context.
兩個解決方案部
刪除第一個查詢的ToList()。
選定的答案。
我選擇了1.由於使用較少的行,並且是一個簡單的解決方案,具有相同的結果。
是第一個引發該異常的查詢,還是第二個? –
第二個查詢拋出異常。如果有辦法做到這一點,我不反對將查詢結合起來。 –
嘗試從第一個查詢中移除.ToList()。 – Harsh