我有2個實體「UserProfile」和「Agent」,它們是1-many關係。我想通過提供userProfileEntityKey來執行查詢以獲取代理列表。當我運行它時,我得到了這個「LINQ to Entities不支持指定的類型成員'EntityKey'」錯誤。LINQ to Entities不支持指定的類型成員'EntityKey'
public IQueryable<Agent> GetAgentListByUserProfile(EntityKey userProfileEntityKey)
{
ObjectQuery<Agent> agentObjects = this.DataContext.AgentSet;
IQueryable<Agent> resultQuery =
(from p in agentObjects
where p.UserProfile.EntityKey == userProfileEntityKey
select p);
return resultQuery;
}
那麼,什麼是正確的方法來做到這一點?我是否使用p.UserProfile.UserId = UserId?如果是這樣的話,那就不再是概念了。或者我應該寫對象查詢,而不是LINQ查詢?