簡體   English   中英

db4o:如何在沒有c#原始類的情況下從數據庫檢索對象?

[英]db4o: How to retrieve objects from DB without having the original class in c#?

我有一些應用程序創建的db4o文件(我沒有源文件),我需要從該文件中獲取所有數據。

在教程中看到的所有示例中,都有用於檢索對象的類,但是如果我沒有這些類怎么辦?

您可以使用LINQPad和我的驅動程序進行嘗試: http ://www.gamlor.info/wordpress/2011/03/db4o-driver-for-linqpad/

否則,您可以探索db4o反射API:

假設您沒有課程,只想看一切。 這樣的事情(不記得確切的API):

IQuery query = container.Query();
IEnumerable allObjects = query.Execute();

foreach(Object item : allObjects){

    GenericObject dbObject = (GenericObject)item; // Note: If db4o finds actuall class, it will be the right class, otherwise GenericObject. You may need to do some checks and casts
    dbObject.GetGenericClass().GetDeclaredFields(); // Find out fields
    object fieldData = dbObject.Get(0); // Get the field at index 0. The GetDeclaredFields() tells you which field is at which index
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM