I have 3 sql tables SourceKeys, Channels, and ChannelTypes. These tables are queried and their data is stored in datatables in my dataset.
What I need is this:
SELECT ...
FROM ChannelTypes ct
LEFT OUTER JOIN Channels ch ON ct.channelTypeID = channelTypeID
LEFT OUTER JOIN SourceKeys sk ON ch.channelID = sk.channelID
but in linq form... I'm a bit new to linq and read a bunch of msdn articles but just need some help to get over the hump.
var sourceKeyQuery =
from ct in ds.Tables["ChannelTypes"].AsEnumerable()
join ch in ds.Tables["Channels"].AsEnumerable()
on ct.Field<int>("channelTypeID") equals ch.Field<int>("channelTypeID") into gj1
from channels in gj1.DefaultIfEmpty()
join sk in ds.Tables["SourceKeys"].AsEnumerable()
on channels.Field<int>("channelID") equals sk.Field<int>("channelID") into gj2
from sourceKeys in gj2.DefaultIfEmpty()
orderby ct.Field<string>("channelType"),
channels.Field<string>("channel"),
sourceKeys.Field<string>("sourceKeys")
select (sourceKeys == null)?null:sourceKeys.Field<int?>("sourceKeyID");
The error I'm getting says channels.Field<int>("channelID")
cannot be null... i tried using <int?>
but it didnt work.