EJDB C#绑定
我在EJDB的C#绑定方面遇到了一些问题 这很可能只是一个理解问题 我想使用ejb来存储一些非常基本的数据。每当我启动程序时,这些数据都将可用。(持续) 运行代码时没有错误。当query.Find()不返回任何内容时,它在结尾跳过foreach。 如果你看一下评论,你会发现我对“myCollection”做了两次查询。一次是在我插入数据之后,一次是在第二个方法之后。 第一个计数返回1,第二个计数返回0。指示这两个方法之间必须有一些数据擦除。我猜是Dispose方法,但是如果我不调用它,db不会关闭,并且当我再次尝试打开它时会出现异常 任何帮助都将不胜感激。ejb是否仅用于运行时数据?还是我必须以某种方式保存数据库?就像一个承诺。还是我关闭数据库时出错了 现在我的代码看起来有点像:EJDB C#绑定,c#,nosql,ejdb,C#,Nosql,Ejdb,我在EJDB的C#绑定方面遇到了一些问题 这很可能只是一个理解问题 我想使用ejb来存储一些非常基本的数据。每当我启动程序时,这些数据都将可用。(持续) 运行代码时没有错误。当query.Find()不返回任何内容时,它在结尾跳过foreach。 如果你看一下评论,你会发现我对“myCollection”做了两次查询。一次是在我插入数据之后,一次是在第二个方法之后。 第一个计数返回1,第二个计数返回0。指示这两个方法之间必须有一些数据擦除。我猜是Dispose方法,但是如果我不调用它,db不会关
static public Data createNewData(Data myData)
{
var myDB = new EJDB("MyDB", EJDB.DEFAULT_OPEN_MODE | EJDB.JBOTRUNC);
myDB.ThrowExceptionOnFail = true;
var data = BSONDocument.ValueOf(new
{
name = myData.Name,
guiName = myData.GuiName
});
myDB.Save("myCollection", data);
//update ID
myData.m_ID = data["_id"].ToString();
//returns 1, => it worked
int count = myDB.CreateQueryFor("myCollection").Count();
//close the DB (as in the example, maybe thats the error? but then how to close the DB?)
myDB.Dispose();
//now calling the second method where the DB is empty again
AllData.updateData();
return myData;
}
static internal void updateData()
{
var myDB = new EJDB("MyDB", EJDB.DEFAULT_OPEN_MODE | EJDB.JBOTRUNC);
myDB.ThrowExceptionOnFail = true;
//just for testing
//returns 0 DB seems to be empty, but i just stored the data in the previous method?!
int count = myDB.CreateQueryFor("myCollection").Count();
//get all data stored in myCollection
var query = myDB.CreateQueryFor("myCollection");
//this always finds nothing. the db seems to be empty
using (var cur = query.Find())
{
//this foreach gets skipped as there is cur is empty
foreach (var e in cur)
{
BSONDocument rdoc = e.ToBSONDocument();
Data newData = Data.createNewDataFromBSONDocument(rdoc);
AllData.Add(newData);
}
}
myDB.Dispose();
query.Dispose();
}
哎呀,我发现了错误。我真可耻,一个人不应该不假思索地照搬这个例子
打开数据库时选择了EJDB.JBOTRUNC,它只是删除了以前的所有数据