You need to access all this through your DataContext object.
Have a look in the generated c# file for your dbml and look for EntitySet collections marked with an Association attribute - there should be one in Gallary and Image, and 2 in GallaryImage. If the dbml is generated correctly, you should be able to do something like the following -
Off the top of my head, i'm pretty sure that the design surface will name the plural of Gallery as Gallerys instead of Galleries, so it's not a typo -
DataConext dc = new GalleryDataConext();
foreach (Gallery g in dc.Gallerys)
{
Console.Writeline("gallery id " + g.Id.ToString());
foreach(GalleryImage gi in g.GalleryImages)
{
Console.Writeline("galleryimage id " + gi.Id.ToString());
foreach(Image i in gi)
{
Console.Writeline("image id " + i.Id.ToString());
}
}
Even without the associations, the following should work -
int GalID = 1;
GalleryDataConext dc = new GalleryDataConext()
var pics = from g in dc.Gallary
join gi in dc.GallaryImages on g.Id equals gi.GallaryId
join i in dc.Images on gi.ImageId equals i.Id
where g.Id = GalID
select i;
To get gallaries from a pic id, you'd do -
int PicID = 1;
var gals = from g in dc.Gallary
join gi in dc.GallaryImages on g.Id equals gi.GallaryId
join i in dc.Images on gi.ImageId equals i.Id
where i.Id = PicID
select g;
The above will return you an IQueryable<Gallary>
and will do the sql query when you enumerate over it.