db4o - 如何查询通用接口
我没有在任何地方找到是否可以从 Db4o 查询所有实现某些通用接口的对象,
例如: 要查询实现 IList
的所有对象,我尝试过:
var items = from IList<object> item in session
select item;
但这不会返回数据库中的所有列表(仅返回专门实现 IList
)除了从数据库查询所有对象、循环它们并手动评估对象之外,还有什么方法可以做到这一点? (在这种情况下我必须穿过数百万个物体)
谢谢
I didn't find anywhere whether is possible to query from Db4o all objects implementing some generic interface
for example:
to query all objects implementing IList<T>
, I tried:
var items = from IList<object> item in session
select item;
but this doesn't return all lists in database (only the ones which implements specificaly IList<object>
)
Is there any way to do it other then query all objects from database, loop them and evaluate the object manually? (I would have to pass through milions of objects in this case)
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要查询属于 IList<> 的任何实例的所有对象。类型。或其他服装通用类型。
我认为目前这是不可能的。原因是 db4o 将 List<> 的每个实例视为一个实例。作为它自己的类型。所以List和List是以两种不同的类型存储的。这直接涉及到 db4o 中的元数据存储,这些元数据存储是单独存储的。这也意味着不同 List<> 的所有实例不存在共享索引。类型。
顺便说一句,在 Java 中,情况正好相反,所有类型的 List<> 都可以。被视为相同类型,因为在 Java 中泛型不会在运行时反映。
因此,您基本上需要检查所有不同类型的 List<> 。自己获取所有实例。
对于您自己的类型,我将创建一个抽象的非泛型类,泛型实例将继承该类。然后您可以查询并获取所有通用子类型。请注意,这不适用于接口,因为 db4o 不会索引或保留接口的元信息。
You want to query for all objects which are any instance of the IList<> type. Or other costume generic types.
In my opinion this is not possible at the moment. The reason is that db4o treats each instance of a List<> as its own type. So a List and a List are stored a two different types. This goes right down to the meta data storage in db4o, where those are stored separately. This also means that there not shared index for all instance of the different List<> types.
Btw in Java it is the other way around, all types of List<> are treated as the same type, since in Java generics are not reflected at runtime.
So, you basically need to go over all the different types of List<> yourself to get all instances.
For your own types I would create an abstract non generic class which the generic instance inherit. Then you can query for that and get all generic subtypes. Note that this doesn't work for interfaces, since db4o doesn't index or keep meta-infos for interfaces.