Microsoft Cloud Authors: Lori MacVittie, Elizabeth White, Yeshim Deniz, Serafima Al, Janakiram MSV

Related Topics: Microsoft Cloud

Microsoft Cloud: Article

An Exploration of the ObjectSpaces Framework

Accessing data through application business domain objects

With the release of the alpha bits of ADO.NET 2.0 and Visual Studio 2005, Microsoft is experimenting with a framework that provides .NET programmers with a new way to access and work with relational data. Traditionally, passing and persisting data to the data storage layer has been very data-centric, as it consisted of thinking of data in terms of tables, rows, and columns. This conflicts with the object-centric paradigm of the business logic layer where data is defined in terms of objects and properties. As a result, a lot of custom code is written and maintained to couple the data-centric database storage layer to the object-centric business layer. ObjectSpaces enables you to work with the data through the business- level objects that make up the application domain. The classes that make up the ObjectSpaces architecture allow you to abstract out the complexity of the data-centric syntax of the storage medium from the object-oriented developer. This article introduces the ObjectSpaces framework and demonstrates the fundamentals of implementing ObjectSpaces in a .NET application.

ObjectSpaces: An Introduction
A valid question you may be asking is, "What is the ObjectSpaces framework and what problem is it trying to solve?" Quite simply, ObjectSpaces is technology built on top of ADO.NET, to provide data-access support. With the addition of ObjectSpaces, ADO.NET supports three main forms of data access technology. The most obvious and utilized data-access technology is the DataSet/DataReader. The strength of DataSets and DataReaders are that they incorporate a relational model common to most relational back-end databases and fully expose the database functionality. They also provide the highest performance compared to the other data-access technologies.

Another data-access technology is SQLXML. The strength of SQLXML is its ability to decouple the data from the database schema. When data needs to be exposed as XML structures, such as Web services and B2B applications, SQLXML is generally the data access of choice. It also provides the ability to map the same data to different schemas for content publishing to various vertical industry standards.

ObjectSpaces is similar to SQLXML in that it decouples the data structure from the database schema. The difference is that ObjectSpaces exposes the schema based on the business-level objects in the application as opposed to XML structures. ObjectSpaces is the way to go if the application has a strong business object layer and the data needs exposure through an object model instead of a relational model.

As you can see, each of these data access technologies exposes a different set of functionalities to solve various problems. It is important that you understand the strengths and weaknesses of each of the data-access technologies. Armed with this knowledge, you will make better decisions on how to design your data-access strategies.

ObjectSpaces is an object-relational mapping (O/RM) framework embedded in ADO.NET. Although O/RM technologies are not new and several third parties offer .NET add-ins, Microsoft is including ObjectSpaces as part of the .NET Framework. O/RM essentially couples the application's object model with the underlying data storage engine. To accomplish this, the O/RM engine uses a mapping file to make the necessary translations.

The ObjectSpaces engine uses an XML mapping file that translates from an object query/update call into the SQL query/update call. By moving the mapping schema into a separate file, objects can be persisted and retrieved from the data storage without writing provider-specific code. Object-oriented programmers can work with the object data using familiar object-oriented syntax.

Mapping Object Relationships
For O/RM to work, the O/RM engine needs a mapping file that defines the schema of the data base, the schema of the objects, and how the schema is mapped between the two. To demonstrate the creation of a mapping file we will create a simple object type – product – and map it to the products table in the Northwind database. Listing 1 (the listings are online at www.sys-con.com/dotnet/sourcec.cfm) defines the product class. Listing 2 shows the XML mapping file used to define the mapping between the product class and the products table.

The database definition schema is defined within the <m:Data Source> </m:DataSource > tags. The object schema is defined within the <m:DataTarget> </m:DataTarget> tags. Notice that object schema tags contain the prefix "osd:" as a namespace alias. (One little caveat of which to be careful: when exposing your data through properties of the class instead of public fields, you need to specify the property as an alias attribute of the field <osd:member> node.)

The mapping schema is defined within the <m:Mappings> </m:Mappings> tags. As you probably realized, creating even the simplest of mapping files is not a trivial exercise and when creating one by hand, using note pad is not practical. Fortunately, Microsoft will provide a mapping utility that will greatly simplify this process. Figure 1 shows the current incarnation of the mapping utility, which allows you to drag and drop data tables and classes onto the design surface and visually create the mappings.

ObjectSpaces supports complex mappings such as one-one, one-many, and many-many. As an example of a one-many mapping, a Supplier class is defined that is related to the Product class. To link the parent Supplier class with the child Product class, a property of a type that implements the IList interface is defined. The child class links back to the parent class through a property of type parent in the child class.

Listing 3 contains the definitions of the Supplier and Product classes. To support this relationship, the mapping file is updated to include an <osd:ObjectRela tionship> node that includes a schema defining the relationship between the two objects. The updated schema also reflects the definition relating the Supplier table and the Products table from the Northwind Database. Listing 4 shows the updated nodes added to the mapping files.

Retrieving Objects
To use ObjectSpaces, the application needs to reference the System.Data.ObjectSpaces and System.Data.SqlXml assemblies. The ObjectSpace class acts as the broker between the database model and the object model. An ObjectSet is then instantiated through the GetObjectSet method of an ObjectSpace. The ObjectSet represents a collection of objects returned from the GetObjectSet method. The GetObjectSet method takes a parameter of type string, which defines the query used to retrieve the object data (more about this later). Listing 5 demonstrates retrieving and populating a collection of Product objects and displaying their ProductName properties in a list. Figure 2 shows the resulting list. The ObjectSet provides functionality similar to the DataSet. For example, it enables data binding to Windows Forms controls and tracking values for optimistic concurrency checking.

Along with the features provided with the ObjectSet, the results of an object query can be returned through an ObjectReader. The ObjectReader is analogous to the DataReader. It provides a forward-only, low-overhead stream of objects. It is useful when you need to read the data out of the Objects but do not need the overhead of persisting the entire object model. Listing 6 demonstrates retrieving the ProductName property of the Product objects and loading them into a list box using an ObjectReader.

Spans and Delay Loading
Spans and delay loading provide more control over the way the object model is loaded. A span identifies the related objects that are returned along with the objects retrieved by the query. For example, when retrieving the Supplier objects, you can use a span to retrieve the associated products. Listing 7 uses a span to retrieve both the Suppliers and their related Products. Each Supplier's CompanyName property is loaded into a TreeView control as a parent node and the associated Products' ProductNames are loaded as the corresponding child nodes. (Remember that the relationship between these objects must also be modeled in the mapping file.) Figure 3 shows the resulting TreeView display.

For performance reasons, there are times when you do not want to load the related objects immediately. ObjectSpaces supports on-demand loading of the related objects using delayed loading. To implement delayed loading, ObjectSpaces provides two classes that provide a wrapper for the classes in the relationship. The ObjectList class provides delayed loading for a one-many relationship and the ObjectHolder class provides delayed loading for a one-one relationship. Listing 8 shows the Supplier class altered to take advantage of delayed loading. Notice the Products field and the Products property are of type ObjectList. Listing 9 shows the loading of a second list box depending on the value selected in the first list box by delayed loading. Figure 4 shows the resulting list boxes.

Querying Objects with OPath
One of the most interesting aspects of the ObjectSpaces framework is the development of an object query language. OPath allows object-oriented programmers the ability to use familiar object-oriented syntax to query the object model. It includes a rich feature set of literals, operators, predicates, and functions. Using OPath, programmers can construct complex queries using the syntax with which they are most comfortable working, while giving the ObjectSpaces engine the arduous task of converting it to the database querying syntax. In the previous examples, an empty string was passed in with the instantiation of the ObjectQuery object. This results in pulling back the entire object set. Listing 10 demonstrates restricting the result set using an OPath query. Listing 11 contains the ensuing SQL generated by the ObjectSpaces engine. Although I can only scratch the surface of the OPath query language in this article, look for a future article devoted to this topic as the language matures.

With the ObjectSpaces framework, Microsoft is providing an intriguing technology to .NET programmers. The classes that make up the ObjectSpaces architecture provide the ability to abstract out the complexity of the data centric syntax of the storage medium. Object-oriented developers can work with the data using familiar OOP syntax and the object centric model of the business layer. ObjectSpaces is evolving to offer a rich feature set including object/relational mapping, delayed loading, data binding, transactional support, and an optimistic concurrency model.

The possibilities of this technology are fascinating and I hope that this article gave you a feel for the direction in which Microsoft is moving with the ObjectSpaces framework. Unfortunately, we will have to wait a little longer for the full release of this framework. Microsoft has recently announced that the release of the ObjectSpaces framework is now aligned with the WinFS/Longhorn release timeframe. On the upside, this indicates that ObjectSpaces is an integral part of Microsoft's future and will only get better and more mature over time.

More Stories By Dan Clark

Dan is a Microsoft Certified Trainer, Microsoft Certified Solution Developer, and a Microsoft Certified Database Administrator. For the past seven years he has been developing applications and training others how to develop applications using Microsoft technologies. Dan has been developing and training Microsoft's .NET technologies since the early betas. He has recently authored the book "An Introduction to Object-Oriented Programming with Visual Basic .NET," published by Apress.

Comments (4) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

Most Recent Comments
Zeeshan Shakeel 08/13/07 09:05:27 AM EDT

interesting article, fantastic effort, welldone Dan
take care

Santosh Benjamin 11/22/04 09:51:38 AM EST

Sorry i missed that part of the conclusion. I agree that its good for the maturity of the framework, but i think they will also lose some momentum in this space to open source technologies such as NHibernate etc. Anyway, all we can do is wait and see. Perhaps it will turn out to be a killer app!!

Dan Clark 07/07/04 02:34:03 PM EDT

Santosh - You are correct that ObjectSpaces has been stripped from ADO 2.0, as I mentioned in the conclusion. The good news is that it will resurface in the near future.

Santosh Benjamin 07/07/04 10:29:08 AM EDT

Interesting article. As far as i know though, ObjectSpaces is not in ADO.NET 2.0 and has been moved to the Longhorn/Orcas timeframe. See the following articles

@ThingsExpo Stories
Michael Maximilien, better known as max or Dr. Max, is a computer scientist with IBM. At IBM Research Triangle Park, he was a principal engineer for the worldwide industry point-of-sale standard: JavaPOS. At IBM Research, some highlights include pioneering research on semantic Web services, mashups, and cloud computing, and platform-as-a-service. He joined the IBM Cloud Labs in 2014 and works closely with Pivotal Inc., to help make the Cloud Found the best PaaS.
As data explodes in quantity, importance and from new sources, the need for managing and protecting data residing across physical, virtual, and cloud environments grow with it. Managing data includes protecting it, indexing and classifying it for true, long-term management, compliance and E-Discovery. Commvault can ensure this with a single pane of glass solution – whether in a private cloud, a Service Provider delivered public cloud or a hybrid cloud environment – across the heterogeneous enter...
Cloud-enabled transformation has evolved from cost saving measure to business innovation strategy -- one that combines the cloud with cognitive capabilities to drive market disruption. Learn how you can achieve the insight and agility you need to gain a competitive advantage. Industry-acclaimed CTO and cloud expert, Shankar Kalyana presents. Only the most exceptional IBMers are appointed with the rare distinction of IBM Fellow, the highest technical honor in the company. Shankar has also receive...
"We view the cloud not as a specific technology but as a way of doing business and that way of doing business is transforming the way software, infrastructure and services are being delivered to business," explained Matthew Rosen, CEO and Director at Fusion, in this SYS-CON.tv interview at 18th Cloud Expo (http://www.CloudComputingExpo.com), held June 7-9 at the Javits Center in New York City, NY.
The Founder of NostaLab and a member of the Google Health Advisory Board, John is a unique combination of strategic thinker, marketer and entrepreneur. His career was built on the "science of advertising" combining strategy, creativity and marketing for industry-leading results. Combined with his ability to communicate complicated scientific concepts in a way that consumers and scientists alike can appreciate, John is a sought-after speaker for conferences on the forefront of healthcare science,...
WebRTC is great technology to build your own communication tools. It will be even more exciting experience it with advanced devices, such as a 360 Camera, 360 microphone, and a depth sensor camera. In his session at @ThingsExpo, Masashi Ganeko, a manager at INFOCOM Corporation, introduced two experimental projects from his team and what they learned from them. "Shotoku Tamago" uses the robot audition software HARK to track speakers in 360 video of a remote party. "Virtual Teleport" uses a multip...
Data is the fuel that drives the machine learning algorithmic engines and ultimately provides the business value. In his session at Cloud Expo, Ed Featherston, a director and senior enterprise architect at Collaborative Consulting, discussed the key considerations around quality, volume, timeliness, and pedigree that must be dealt with in order to properly fuel that engine.
In his session at Cloud Expo, Alan Winters, U.S. Head of Business Development at MobiDev, presented a success story of an entrepreneur who has both suffered through and benefited from offshore development across multiple businesses: The smart choice, or how to select the right offshore development partner Warning signs, or how to minimize chances of making the wrong choice Collaboration, or how to establish the most effective work processes Budget control, or how to maximize project result...
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
IoT is rapidly becoming mainstream as more and more investments are made into the platforms and technology. As this movement continues to expand and gain momentum it creates a massive wall of noise that can be difficult to sift through. Unfortunately, this inevitably makes IoT less approachable for people to get started with and can hamper efforts to integrate this key technology into your own portfolio. There are so many connected products already in place today with many hundreds more on the h...
DXWorldEXPO LLC announced today that ICC-USA, a computer systems integrator and server manufacturing company focused on developing products and product appliances, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, in New York City. ICC is a computer systems integrator and server manufacturing company focused on developing products and product appliances to meet a wide range of ...
JETRO showcased Japan Digital Transformation Pavilion at SYS-CON's 21st International Cloud Expo® at the Santa Clara Convention Center in Santa Clara, CA. The Japan External Trade Organization (JETRO) is a non-profit organization that provides business support services to companies expanding to Japan. With the support of JETRO's dedicated staff, clients can incorporate their business; receive visa, immigration, and HR support; find dedicated office space; identify local government subsidies; get...
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
Explosive growth in connected devices. Enormous amounts of data for collection and analysis. Critical use of data for split-second decision making and actionable information. All three are factors in making the Internet of Things a reality. Yet, any one factor would have an IT organization pondering its infrastructure strategy. How should your organization enhance its IT framework to enable an Internet of Things implementation? In his session at @ThingsExpo, James Kirkland, Red Hat's Chief Archi...
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
Personalization has long been the holy grail of marketing. Simply stated, communicate the most relevant offer to the right person and you will increase sales. To achieve this, you must understand the individual. Consequently, digital marketers developed many ways to gather and leverage customer information to deliver targeted experiences. In his session at @ThingsExpo, Lou Casal, Founder and Principal Consultant at Practicala, discussed how the Internet of Things (IoT) has accelerated our abilit...
Organizations planning enterprise data center consolidation and modernization projects are faced with a challenging, costly reality. Requirements to deploy modern, cloud-native applications simultaneously with traditional client/server applications are almost impossible to achieve with hardware-centric enterprise infrastructure. Compute and network infrastructure are fast moving down a software-defined path, but storage has been a laggard. Until now.
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
The best way to leverage your CloudEXPO | DXWorldEXPO presence as a sponsor and exhibitor is to plan your news announcements around our events. The press covering CloudEXPO | DXWorldEXPO will have access to these releases and will amplify your news announcements. More than two dozen Cloud companies either set deals at our shows or have announced their mergers and acquisitions at CloudEXPO. Product announcements during our show provide your company with the most reach through our targeted audienc...
@DevOpsSummit at Cloud Expo, taking place November 12-13 in New York City, NY, is co-located with 22nd international CloudEXPO | first international DXWorldEXPO and will feature technical sessions from a rock star conference faculty and the leading industry players in the world.