Joins

6 views
Skip to first unread message

Chris Richard

unread,
Jul 2, 2008, 11:38:06 AM7/2/08
to linqtordf-discuss
Came across this blog post of yours from a year ago:

http://aabs.wordpress.com/2007/06/20/groupjoins-in-linq/

Is this implemented in linqtordf?

Andrew Matthews

unread,
Jul 2, 2008, 5:59:29 PM7/2/08
to linqtord...@googlegroups.com
Hi Chris,

Yes it is - in the most recent version. Although the syntax doesn't use the 'join' keyword.

A child to parent relationship is represented using the LINQ to SQL EntityRef class like so:

private EntityRef<Album> _Album { get; set; }
[OwlResource(OntologyName = "Music", RelativeUriReference = "isTrackOn")]
public Album Album
{
get
{
if (_Album.HasLoadedOrAssignedValue)
return _Album.Entity;
if (DataContext != null)
{
var ctx = (MusicDataContext)DataContext;
_Album = new EntityRef<Album>(from a in ctx.Albums where a.HasInstanceUri(AlbumUri) select a);
return _Album.Entity;
}
return null;
}
}

And a parent to child relationship is represented using an EntitySet:

private EntitySet<Track> _Tracks = new EntitySet<Track>();
[OwlResource(OntologyName = "Music", RelativeUriReference = "isTrackOn")]
public EntitySet<Track> Tracks
{
get
{
if (_Tracks.HasLoadedOrAssignedValues)
return _Tracks;
if (DataContext != null)
{
_Tracks.SetSource(from t in ((MusicDataContext)DataContext).Tracks where t.AlbumName == Name select t);
}
return _Tracks;
}
}

This is all code generated by the designer.

You would use it like so:

Var ctx = new MusicDataContext(urlOfSparqlStore);
var q = from t in ctx.Tracks
where t.Title.StartsWith("California")
select t;

foreach(var track in q){
console.WriteLine(track.Title + " is on album " + track.Album.Name);
}

HTH

Regards,

Andrew

Reply all
Reply to author
Forward
0 new messages