Spans in ObjectSpaces

Because the documentation on ADO.NET ObjectSpaces is pretty thin, I will start posting all things that I find out about ObjectSpaces, especially if undocumented at this point in time. Scott S Sikora posted a question in news:microsoft.public.objectspaces relating to spans for ObjectQueries. He has multiple relations in his object hierarchy and wonders how to retrieve the child objects from both relations.

Well, spans contain comma separated members that list the names of the properties for the parent members of the relationships. The list must not end with a (trailing) comma, or you will get a QueryException. For example: suppose your parent class Person has two one-to-one relationships to child objects called theManager and theSupervisor of type Manager and Supervisor respectively. Querying for both of these would become:

SqlConnection con = new SqlConnection(“DATA SOURCE=(local);” + 
ObjectSpace os = new ObjectSpace(“MappingSchema.xml”, con);

Person p = null;
  p = (Person)os.GetObject(typeof(Person), “ID=1”,
      “theManager, theSupervisor”);
catch (ObjectException ex)
  if (ex.InnerException != null)

Console.WriteLine(p.theManager.Name + ” ” + p.theSupervisor.Name);

I’ve bolded and underlined the span for multiple relationships.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

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

You are commenting using your 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