我有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查询?