An Opinion blog

My Links

Story Categories

Archives

Post Categories

Image Galleries

Login


Remember

Disclaimer

This site is operated by Mike Deem. The opinions expressed here are mine. They are not necessarily my employer's or anybody else's.

Monday, November 17, 2003 #

Relationships

Shawn Smith and Robert McLaws have both asked questions which are hard to answer without explaining WinFS relationships. 

Relationships are used to construct complex structures from individual items. Relationships are just like the sticks that you use between the round spool thingies in Tinker Toys (the spool thingies are the items). A relationship has two ends (we call them source and target), and is always stuck between two items. An item can be the source and target of any number of relationships.

Like items, all relationships have a type. The relationship type hierarchy is rooted in the System.Storage.Relationship type. Also like item types, relationship types can define properties that will be stored with relationship instances. In addition, relationship types can specify the required source and target item types. 

Here is an example relationship type I could use to create a graph of Foo items:

<RelationshipType Name=“FooToFoo“ BaseType=“System.Storage.Relationship“>
    <Source Name=“SourceFoo“ Type=“Foo“/>
    <Target Name=“TargetFoo“ Type=“Foo“/>

    <Property Name=“X“ Type=“System.Storage.WinFSTypes.Int32“/>
</Relationship>

If I have two Foo items, I can relate them as follows:

ItemContext ic = ItemContext.Open();
Foo f1 = ic.FindItemById( id1 );
Foo f2 = ic.FindItemById( id2 );
f1.OutRelationships.Add( new FooToFoo( f2 ) );
ic.SaveChanges();

So, now to answer the questions. WinFS comes with an item type “Folder” and relationship type “FolderMember”. The FolderMember relationship requires that the source item type be Folder but allows the target item type. So, Robert, because items are put in folders using relationships and an item can be targeted by more then one relationship, you can put an item in more then one folder. And Shawn, in WinFS foldering isn't really obsolete, just expanded to encompass a much more powerful concept: relationships.

I'm glossing over some important details, such as the fact that there are three different relationship “modes” (holding, embedding, and relationship) that determine how the relationship controls the lifetime of the target object, how the name space exposed by WinFS is built up, and how security is inherited. Read this section of the Longhorn SDK and look at this PDC presentation for details.

posted @ 11:10 PM | Feedback (10)