Quickstarting ObjectSpace Mapping editor

The March 2004 Community Technology Preview of Visual Studio 2005 has a schema editor for editing mapping files for use in ObjectSpaces. This editor is accessible from a Web project as a Mapping file or as a ObjectMappingFile in a Visual Basic project. You cannot add it from Project, Add New Item… in a C# project. There you will have to copy it from another project or add an existing item. Alternatively you can add an XML file and add the following content:

<?xml version=”1.0″ standalone=”yes”?>
    xmlns:m=”http://schemas.microsoft.com/mapping/2003/06/msd&#8221; >

Once opened you will get a pretty, graphical designer of your mapping file as in the picture below.

The functionality of this editor is not as complete as that of the ObjectSpaces Mapper Utility that was distributed at the PDC for use with the PDC bits. It does, however, do some other neat stuff, to which I’ll get in a moment. The most important thing is that it will edit the new rsd and msd mapping files. From the PDC bits the schemas for these files has changed considerably. The osd schema is still the same (although I did have the impression that some extra attributes where available. Who’s to tell, as the schemas for the mapping files where never made available) and has an unchanged namespace.

Some of the things that you will miss in the editor are:

  • ability to map inheritance trees
  • cannot set type of keys you want to use for object member(s)
  • specify cascade deletes and updates for the relations between objects

The editor consists of two panes. On the left side you have the area that edits both the osd and the msd mappings. The right side edits the relational schema. These two panes can be interchanged by the mini-scrollbar-like button in the Mapping Tool toolbar.

Starting with the object schema you have a choice of importing an existing object schema, or create a new one. When a new schema is created it is stored inline inside the msd file. Importing an existing schema will be referenced as it was in the PDC Mapper Utility. This might be convenient for you if you plan to create ObjectSchema objects, where you will need an osd file (you cannot specify an msd file with an inlined schema. An exception will be thrown stating that the root element is not the correct one).

You can add classes from either the Class View window or the Object Browser by dragging them to the pane. Adding them manually as new classes by right-clicking and selecting it from the context menu is another possibility. In this menu you will find two options: adding a new or existing class. For an existing class the fully qualified name needs to be provided. If found in the project or its references the class and its members are added. A new class will be added without any members.

The relational schema can be created with the same options as the object schema. Dragging the desired tables and views from the Server Explorer or Data Connections window is the easiest way. You can do it manually as well. If you do drag them all related items, such as stored procedures, are also added to the schema under Unmappable Structures. You may want to remove these.

After the object and relational schemas are ready, you can start building your mapping. In middle section of the editor you can add your mappings in the top half, right of where the classes in the object schema are shown. Clicking in the boxes right of the classes (not the members) a Map Candidates dropdown will appear. This holds the available tables and views. After selecting one from the list, you can map members to fields in the same way.

Once you have all mappings in place and save the file, you should be ready to try loading your file into an ObjectMapping. The code is pretty simple:

ObjectMapping map = new ObjectMapping(“mapping.msd”);

If you get no ObjectManagerException on this object construction, you can compliment yourself on a job well done (so far).

In newer builds the reverse engineering options for the object and relational schemas should be available (M3 milestone).

There’s much more to explore in the mapper, but more on that in another entry. Make sure that you select all visual elements of the mapping editor and keep a close watch on the Properties window while you do so. Also, try to drag and drop elements on the panes or onto tree elements. You’ll be amazed what you encounter this way.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s