创建数据库
void CreateOrOpenDb()
{
string DbFile = "db4o.yap";
IObjectContainer Container = Db4oEmbedded.OpenFile(DbFile);
}
这里我们认识两个新朋友:存储对象
Employee _employee = new Employee();
_employee.Name = "Sunth";
Container.Store(_employee);
利用IObjectContainer提供的Store()方法,进行存储操作。
查询对象
IObjectSet Query = Container.QueryByExample(new Employee { Name="Sunth" });
_employee = (Employee)Query.Next();
Db4o提供了4种模式,在这只演示最简单的一种,Query-By-Example(简称QBE)根据模板进行查询
更新对象
IObjectSet Query = Container.QueryByExample(new Employee { Name="Sunth" });
_employee = (Employee)Query.Next();
_employee.Name = "Tom";
Container.Store(_employee);
删除对象
IObjectSet Query = Container.QueryByExample(new Employee { Name="Sunth" });
_employee = (Employee)Query.Next();
Container.Delete(_employee);
利用IObjectContainer提供的Delete()方法,进行删除操作;
结束语