Linq:在选择列表中获取多态实体
我想要执行以下操作...
FROM o IN orders
SELECT new OrderContainer { Contact = (PostalContact) o.Contact }
所以希望您可以看到订单的“联系人”将是派生类型。但不幸的是,它似乎没有进行多态获取!有办法实现这个目标吗?
干杯,伊恩。
I want to do the following...
FROM o IN orders
SELECT new OrderContainer { Contact = (PostalContact) o.Contact }
So hopefully you can see that the order's 'Contact' will be of a derived type. Unfortunately however it doesn't seem to do a polymorphic fetch! Is there anyway of achieving this?
Cheers, Ian.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用扩展方法 .OfType()
编辑:
一种获取完整对象数据的方法,但我怀疑这是否足以满足您的需求。
另一方面,如果将基类(实体)设置为抽象,您可能会发现实体将加载完整的对象。但由于会生成查询,因此不建议这样做。如果您正在研究此问题,您可能需要查看联系人的每个层次结构的 (TPH) 表
Try using the extention method .OfType()
Edit:
a way to get the full object data, but i doubt that this is good enough for your needs.
on the other hand, if you set the base class (entity) to abstract, you may find that entity will load the full objects. but this is not recomended due to the queries that are generated. if you are looking into this you may want to look at (TPH) Table per Hierarchy for your contacts