0

I have the following code which only pulls results from mySqlDataTableB if the SiteUserID exists in mySqlDataTableA.

Otherwise, if the SiteUserID doesn't exist in the mySqlDataTableA, then the result for the "Data" field is always 0 even if there is a different value in mySqlDataTableB.

How can I change it so that it will take the value from mySqlDataTableB even if that SiteUserID doesn't exists in mySqlDataTableA?

var mySqlResult = from mySqlDataRows in mySqlDataTableA.AsEnumerable()
                            join mySqlDataRows2 in mySqlDataTableB.AsEnumerable()
                                on Convert.ToInt32(mySqlDataRows.Field<string>("SiteUserID")) equals
                                Convert.ToInt32(mySqlDataRows2.Field<string>("SiteUserID")) into lj
                            from r in lj.DefaultIfEmpty()
                            select new object[]
                            {
                                mySqlDataRows.Field<string>("SiteUserID"),
                                mySqlDataRows.Field<long>("Posts"),
                                r?.Field<long>("Data") ?? 0
                            };
blizz
  • 4,102
  • 6
  • 36
  • 60
  • 2
    Key phrase: "full outer join". This is one area where LINQ gets wrecked. – user2864740 Jul 13 '16 at 23:14
  • 2
    http://stackoverflow.com/questions/21687454/linq-full-outer-join-with-null-records-c-sharp-from-datatables , https://social.msdn.microsoft.com/Forums/en-US/2fe3d92f-7be5-4999-a240-fc9db7ff0040/full-outer-join-with-linq?forum=linqtosql , http://stackoverflow.com/questions/5489987/linq-full-outer-join , http://stackoverflow.com/questions/2085422/how-to-do-a-full-outer-join-in-linq – user2864740 Jul 13 '16 at 23:15
  • Thanks it helped to come up with an alternative solution – blizz Jul 14 '16 at 11:43

0 Answers0