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(开发者_C百科)
...?
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
}
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.
精彩评论