2
我有這個疑問,其中謂詞Expression<Func<Property, bool>>
和整個查詢返回的IQueryable
:實體框架上的IQueryable投擲選擇「必須還原節點」
var query = _db.PropertyRepository.Get(predicate)
.Include(x => x.Info)
.ThenInclude(x => x.Address)
.Include(x => x.TransactionListingAgents)
.ThenInclude(x => x.Agent)
.ThenInclude(x => x.Person)
.ThenInclude(x => x.Contact)
我想對IQueryable
進行選擇項目到DTO,因爲我需要對這些數據進行一些數據處理。所以,我有這等查詢
query.Select(x => new BasePropertyDTO() {
Id = x.Id,
StreetNumber = x.Info.Address.StreetNumber,
Street = x.Info.Address.StreetName,
});
然而,它拋出一個異常
必須還原節點
我的解決辦法是做ToList()
的Select()
之前並沒有拋出異常了,但現在我正在抓取我不需要的數據。
我發現問題來了,當我嘗試從Info導航屬性或任何導航屬性項目上選擇屬性時,即使我有Include()
調用。
任何想法,爲什麼這是表現這樣或我的查詢出了什麼問題?
升級到1.1.0後,完整的查詢:
query.ToList().Select(x => new BasePropertyDTO() {
Id = x.Id,
StreetNumber = (x.Info != null && x.Info.Address != null) ? x.Info.Address.StreetNumber : "",
Street = (x.Info != null && x.Info.Address != null) ? x.Info.Address.StreetName : "",
City = (x.Info != null && x.Info.Address != null) ? x.Info.Address.City : "",
AgentName = x.TransactionListingAgents.Where(t => t.Agent != null && t.Agent.Person != null && t.Agent.Person.Contact != null && t.ListingId == x.Id && t.BrokerageId == x.BrokerageId).Select(a => a.Agent.Person.Contact.FullName).FirstOrDefault()
});
的AGENTNAME部分拋出
已添加
如果我刪除具有相同鍵的項,我仍然得到
必須還原節點
如果是這樣的話,你應該鏈接到的具體問題。 – DavidG
done.please看到它@DavidG – Sampath
@Sampath,我已經更新到1.1.0,現在我得到另一個異常:具有相同的密鑰項目已被添加。如果我刪除引發該錯誤的列,我仍然會得到「必須是可節點的」異常 – monica