LINQ to SQL does join and left outer join

I have 3 tables. 2 contain lists of files that I need to make UNION to get all unique files, then I want to make a left outer join with the third table to find all the files that are only in the third table, and not in the other 2.

To execute UNION, I have the following:

var imageUnion = (from img in dc.ImageT1
                  select img.filename).Union(
                  from img in dc.ImageT2
                  select img.filename);

Now, to get the files only in the third table, I would make a left outer join as such:

var query = from image in dc.ImageT1
            join active in dc.ActiveImages on image.filename equals 
            active.filename into gj
            from subimage in gj.DefaultIfEmpty()
            where subimage.filename == null
            select new { image.filename, image.size };  

I understand how to make a left outer join just against ONE table, but how do I get the result set of my first query into a left outer join? Basically, instead of making a left outer join with ImageT1, I want to do this against the result of imageUnion.

Thanks!

+3
2

; IEnumerable <string> ( ).

var imageUnion = (from img in dc.ImageT1
                  select new { Filename = img.filename, Size = img.size }).Union(
                  from img in dc.ImageT2
                  select new { Filename = img.filename, Size = img.size });

dc.ImageT1.

, 2 ; , , , ?

public class TempImage
{
    public string Filename { get; set; }
    public int Size { get; set; }
}

var imageUnion = (from img in dc.ImageT1
                  select new TempImage() { Filename = img.filename, Size = img.size }).Union(
                  from img in dc.ImageT2
                  select new TempImage() { Filename = img.filename, Size = img.size });
+4

. - :

var query = from image in imageUnion
            join active in dc.ActiveImages on image.filename equals 
            active.filename into gj
            from subimage in gj.DefaultIfEmpty()
            where subimage.filename == null
            select new { image.filename, image.size };

edit: imageUnion, , ( , ).

+1

Source: https://habr.com/ru/post/1704970/


All Articles