Back to Home

UsefulDB4O in ASP.NET

UsefulDB4O db4o allows you to easily use the ASP.NET environment

  1. You can define different databases in web.config
  2. Access them easily through a static class

Steps to start

  1. Add the required references to your web project:
    • Db4objects.Db4o.dll
    • UsefulDB4O.dll
  2. Add the DB4OHttpModule, inside system/web /httpmodules section on web.config file

    <httpModules>
    	<add name="DB4OHttpModule" type="UsefulDB4O.Web.DB4OHttpModule, UsefulDB4O"/>
    </httpModules>

  3. Add the configuration section “DB4OConfigSection” in the web.config

    <configSections>
    	<section name="db4o" type="UsefulDB4O.ApplicationConfig.DB4OConfigSection"/>
    </configSections>

  4. Sets your databases on db4o section, customizing via attributes 

    <db4o>
      <databases>
        <database
          alias="ProductsDatabase"
          serverType="EmbeddedServer"
          fileDb4oPath="/App_Data/products.db4o"
          />
      </databases>
    </db4o>

    For more information about attributes of the database element, go to this page.
    For more examples, go to this page.
    To see how to control the configuration that opens the database db4o, go to this page.

  5. Get a IObjectContainer instance of the db4o database using the “alias” name. To do this, use the static class UsefulDB4O.Web.DB4ODatabases

    protected void Page_Load(object sender, EventArgs e)
    {
       var productsContainer = UsefulDB4O.Web.DB4ODatabases.GetCurrentContextContainer("ProductsDatabase");
       
       var category = new Category
        {
            CategoryID = Guid.NewGuid(),
            Name = "Cars",
            Products = new Collection<Product>()
        };
                
        productsContainer.Store(category);    	
    }

Index of UsefulDB4O in ASP.NET

Last edited Dec 28, 2010 at 11:58 AM by pacoweb, version 6

Comments

No comments yet.