<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="2" MadCap:lastHeight="120" MadCap:lastWidth="624" MadCap:disableMasterStylesheet="true" MadCap:tocPath="Usage Pitfalls" MadCap:InPreviewMode="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" MadCap:PathToHelpSystem="../../" MadCap:HelpSystemFileName="index.xml" MadCap:SearchType="Stem"> <head><title>Accessing Persistent Classes From Different .NET Applications </title> <script type="text/javascript">/* <![CDATA[ */ window.onload = function(){ var pathToFlash = $('html').attr('MadCap:PathToHelpSystem') + 'Content/Resources/Code/ZeroClipboard.swf'; ZeroClipboard.setMoviePath(pathToFlash); function bindToClipBord(element,content){ var clip = new ZeroClipboard.Client(); clip.setText(content); clip.glue(element); }; if(location.protocol==='file:'){ $('.copylink-marker').remove(); } else{ $('.copylink-marker').each(function(){ var text = $(this).parent().parent().children('.prettyprint').html(); $(this).hover(function(){ bindToClipBord(this,text); }, function(){}); }); } prettyPrint(); }; /* ]]> */</script> <link href="../SkinSupport/MadCap.css" rel="stylesheet" /> <link href="../Resources/Stylesheets/OnlineStyle.css" rel="stylesheet" /> <script src="../SkinSupport/MadCapAll.js"> </script> <script src="../Resources/Code/prettify.js"> </script> <script src="../Resources/Code/lang-vb.js"> </script> <script src="../Resources/Code/jquery.min.js"> </script> <script src="../Resources/Code/ZeroClipboard.js"> </script> </head> <body> <p class="MCWebHelpFramesetLink" style="display: none;"><a href="../../index_CSH.html#usage_pitfalls/accessing_persistent_classes_from_different_.net_applications.htm" style="">Open topic with navigation</a> </p> <div class="MCBreadcrumbsBox"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="../usage_pitfalls.htm">Usage Pitfalls</a><span class="MCBreadcrumbsDivider"> > </span><span class="MCBreadcrumbs">Accessing Persistent Classes From Different .NET Applications</span> </div> <p> <script type="text/javascript">/*<![CDATA[*/document.write('<a href="' + location.href +'">'); document.write("Direct Link"); document.write('</a>');/*]]>*/</script> </p> <p> </p> <h1>Accessing Persistent Classes From Different .NET Applications</h1> <h2>Problem</h2> <p>Accessing db4o database created and filled in with a .NET application or library from another .NET application or library shows an empty database.</p> <h2>Reason</h2> <p>db4o class name format in db4o consists of the full class name and assembly name:</p> <p><code>Namespace.ClassName, AssemblyName</code> </p> <p>Two different .NET applications (libraries) usually have different assembly names. If you do not use <a href="../configuration/common/alias.htm">aliasing</a>, the class name will be appended with the current application assembly name.</p> <h2>Solution</h2> <p>In order to access db4o persistent classes from different applications (libraries) you will need to use an <a href="../configuration/common/alias.htm">Alias</a>. For example:</p> <p><b>Application1.exe ("Application1" assembly):</b> </p> <p><code>objectContainer.Store(new MyClasses.Pilot("David Barrichello",99))</code> </p> <p><code>// internally the class is saved as "MyClasses.Pilot, Application1".</code> </p> <p><b>Application2.exe ("Application2" assembly):</b> </p> <p MadCap:conditions="Primary..NET,Primary.c#,Primary.All languages"> <p>c#:</p> <p><code>// create an <span class="MCPopup"><a href="javascript:void(0);" class="MCPopupSpot" onclick="FMCPopup( event, this ); return false;" MadCap:src="../configuration/common/alias.htm">Alias<img style="border: none;margin-left: 5px;" src="../SkinSupport/ExpandingClosed.gif" MadCap:altsrc="../SkinSupport/ExpandingOpen.gif" class="MCExpandingIcon" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../SkinSupport/ExpandingOpen.gif' ); }" /></a></span> for the MyClasses.Pilot, Application1:</code> </p> <p><code>IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration();</code> </p> <p><code>configuration.Common.AddAlias(new TypeAlias("MyClasses.Pilot, Application1", " MyClasses.Pilot, Application2"));</code> </p> <p><code>IObjectContainer container = Db4oEmbedded.OpenFile(configuration, "reference.db4o");</code> </p> <p><code>// now you query as usual</code> </p> <p><code>IObjectSet result = container.QueryByExample(new Test());</code> </p> </p> <p MadCap:conditions="Global.Primary:cs" /> <p MadCap:conditions="Primary..NET,Primary.VB.NET,Primary.All languages"> <p>VB:</p> <p><code>// create an Alias for the MyClasses.Pilot, Application1:</code> </p> <p><code>Dim configuration As IEmbeddedConfiguration = Db4oEmbedded.NewConfiguration()</code> </p> <p><code>configuration.Common.AddAlias(new TypeAlias("MyClasses.Pilot, Application1", " MyClasses.Pilot, Application2"))</code> </p> <p><code>Dim container As IObjectContainer = Db4oEmbedded.OpenFile(configuration, "reference.db4o")</code> </p> <p><code>// now you query as usual</code> </p> <p><code>Dim result As IObjectSet = container.QueryByExample(New Test())</code> </p> </p> <p MadCap:conditions="Global.Primary:vb" /> <p>For more information see <a href="../platform_specific_issues/class_name_format_in_.net.htm">Class Name Format In .NET</a> and <a href="../configuration/common/alias.htm">Aliases</a>.</p> <script type="text/javascript" src="../SkinSupport/MadCapBodyEnd.js"> </script> </body> </html>