Application Example of DB4object.net (object-oriented database)

Source: Internet
Author: User
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}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.