views:

50

answers:

2

I can't seem to translate this to LINQ:

    select stuff
    FROM history INNER JOIN profiles ON history.username = profiles.username 
    LEFT OUTER JOIN files ON history.fileid = files.filename 
    LEFT OUTER JOIN streams ON streams.identifier = history.fileid
    LEFT OUTER JOIN galleries ON galleries.identifier = history.fileid, subscribers 
    WHERE stuff

I'm having a hard time following examples of left outer joins. They don't explain whats going on, just what to do in their hypothetical situation. Any help / explanations would be much appreciated.

Here's how I started, the last line (from files in JoinedFiles.DefaultIfEmpty()) won't let me compile. 'Type inference failed in the call 'SelectMany' it says. Why so complicated? =(

    var x = from h in db.Histories
    join prof in db.profiles on h.username equals prof.username
    join files in db.NeebitFiles on h.fileid equals files.filename into JoinedFiles
    from files in JoinedFiles.DefaultIfEmpty()
    ...?
+1  A: 

Get yourself a copy of Linqer (www.sqltolinq.com). It will translate almost any T-SQL statement to Linq. It's not free, but it's not expensive. And you have a 30 day trial.

Randy Minder
While I appreciate this greatly, it doesn't address my issue of understanding. Thanks tho, Im going to try this out. +1
Blankasaurus
+1  A: 

Yeah I've never had much luck either. For joins I do

(from a in db.A
where ...
select new 
{
  a.whatever,
  (from b in db.B where B.AID = A.AID select b.value).First(), //first for inner join
(from c in db.C where C.AID = A.AID select c.value).FirstOrDefault() //firstordefault for outer joins
}
Biff MaGriff
I used this. Not exactly what I was asking for, but I like it a lot better, way easier to make sense of what is going on.
Blankasaurus