Step 1: create associations between tables. You will know that this is done correctly when
- Gallery class has GalleryImages property
- the GalleryImage class has the Gallery and image property (note, single)
- The Image class has the GalleryImages property.
http://msdn.microsoft.com/en-us/library/bb629295.aspx
Step 2: To get a list of galleries:
using (CustomDataContext myDC = new CustomDataContext)
{
List<Gallery> result = myDC.Galleries.ToList();
}
Step 3: then the user clicks on the gallery and you want its images:
using (CustomDataContext myDC = new CustomDataContext)
{
List<Image> result = myDC.Galleries
.Where(g => g.Id = selectedGallery.Id);
.SelectMany(g => g.GalleryImages)
.Select(gi => gi.Image)
.ToList()
}
Step 4: Then the user clicks on the image and you want his gallery:
using (CustomDataContext myDC = new CustomDataContext)
{
List<Gallery> result = myDC.Images
.Where(i => i.Id = selectedImage.Id);
.SelectMany(i => i.GalleryImages)
.Select(gi => gi.Galleries)
.ToList()
}
If you just want to download the entire database, do the following:
using (CustomDataContext myDC = new CustomDataContext)
{
DataLoadOptions dlo = new DataLoadOptions();
dlo.LoadWith<Gallery>(g => g.GalleryImages);
dlo.LoadWith<GalleryImage>(gi => gi.Image);
myDC.LoadOptions = dlo;
List<Gallery> result = myDC.Galleries.ToList();
}
After that, the entire graphic will be downloaded and connected for your use.