0

since DefaultIfEmpty() is not supported, what is the proper way of doing a left join?

2 Answers 2

0

Hard to say how to solve your problem, since you don't say what it is, but generally:

var q = from i in Context.Invoices
        select new 
        {
            Number = i.Number,
            ItemNumbers = from il in i.Lines
                          select il.Number
        }

LINQ to Entities will coalesce nulls, so you get an empty collection if there are no invoice line items.

Now this produces a graph, rather than a tabular result set. My wild guess is that's what you want, since when you work in LINQ to Entities you generally want to work with objects, rather than tabular SQL results. But like you said, it's hard to be more specific without knowing the precise problem you're trying to solve.

2
  • when I put in many field from the same table, the end result,(sql query) use a lot of unionall stuff
    – Fredou
    Oct 6, 2009 at 15:59
  • I can't suggest a good answer based on so little information. Oct 6, 2009 at 16:36
0

in the end, I used the let way with .FirstOrDefault()

from myothertable
where....
let var = (query).FirstOrDefault()
select new {otherfield, var.field1, var.field2}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.