LINQ to Entites 和 ObjectQuery
我有一个与 Person_Addresses
具有 1 : N 关系的 Person 实体(字段:PersonID
、AddressID
、ValidFrom
) 。我想获取所有 Person
记录以及关联的 Person_Addresses
以及最新的 ValidFrom。我应该如何使用 ObjectQuery 或 IQueryable 来执行此操作?
编辑: 我提到了 ObjectQuery
和 IQueryable
,因为我想有一个使用扩展方法的解决方案(我认为,这就是它的调用方式)。另外我忘了提及我正在使用 Entity Framework 生成实体。我想获得一个 person 对象,它的 person_adress 成员已急切地加载。
以下是实体结构: 个人成员:int id、字符串名字、字符串姓氏、Partner_Address 伙伴地址
Person_Address 成员:int personid
、int adressid
、date validfrom
I have Person entity which has a 1 : N relationship with Person_Addresses
(fields: PersonID
, AddressID
, ValidFrom
). I want to get all Person
records and associated Person_Addresses
with only latest ValidFrom. How should I do this using ObjectQuery or IQueryable?
Edit:
I mentioned ObjectQuery
and IQueryable
, because I wanted to have a solution using extension methods (I think, that how it's called). Also I forgot to mention that I'm using Entity Framework where I have the entities generated. I want to get a person object which has it's person_adress member eagerly loaded.
Here are the entities structure:
Person members: int id, string firstname, string lastname, Partner_Address partneradress
Person_Address members: int personid
, int adressid
, date validfrom
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试以下操作。
我有以下实体。
然后触发以下查询。
我发现它在一些测试数据上运行良好。
如有任何疑问,请告诉我。
Try the following.
I have the following entities.
Then fire the following query.
I found it to be working fine with some test data.
Let me know in case of any concern.