DB4Object does not have much magic. I hope you will have a general understanding after reading it like me, this article is also made up of the simplest call examples by reading some friends' articles in the garden, without too many intentions, I only hope you can get started quickly after reading my example.
Example: 1
2/** // <summary>
3 // load the db4object Database
4 /// </summary>
5 /// <param name = "filename"> </param>
6 public void LoadDb4o (string filename)
7 {
8 if (! Filename. EndsWith (". yap") filename = filename + ". yap ";
9 If (! System. Io. file. exists (filename) throw new exception ("the file to be loaded does not exist! ");
10 iobjectcontainer DB = db4ofactory. openfile (filename );
11 try
12 {
13 iobjectset result = dB. Get (New exportrule ());
14 set (result. Next () as exportrule );
15 System. Console. WriteLine ("ExportRule LoadDb4o from" + filename );
16}
17 catch (Exception ex)
18 {
19 System. Console. WriteLine ("Error: An Error occurred while retrieving the ExportRule object! "+ Ex. Message );
20}
21 finally
22 {
23 db. Close ();
24}
25}
26
27/*** // <summary>
28 /// save to db4object Object Database
29 /// </summary>
30 /// <param name = "filename"> </param>
31 public void SaveDb4o (string filename)
32 {
33 if (! Filename. EndsWith (". yap") filename = filename + ". yap ";
34 if (System. IO. File. Exists (filename) System. IO. File. Delete (filename );
35 Db4oFactory. Configure (). ObjectClass (typeof (ExportRule). CascadeOnUpdate (true );
36 IObjectContainer db = Db4oFactory. OpenFile (filename );
37 try
38 {
39 db. Set (this );
40 db. Commit ();
41 System. Console. WriteLine ("ExportRule SaveDb4o to" + filename );
42}
43 catch (Exception ex)
44 {
45 System. Console. WriteLine ("Error: An Error occurred while saving the ExportRule object! "+ Ex. Message );
46}
47 finally
48 {
49 db. Close ();
50}
51}
52 # endregion
53}