質問

I've been trying to perform a Left Join kind of expression in LINQ to Entities, however the DefaultIfEmpty method works differently to what I expected - it returns an empty row for each CounterNo that doesn't have a match in the Readings table.

var leftjoin = from counter in database.Counters
               join reading in database.Readings
               on counter.CounterNo equals reading.CounterNo into gj
               from x in gj.DefaultIfEmpty()
               select x;

This way I don't know which rows from the Counters table don't have a corresponding row the Readings table.

How do I make this work?

役に立ちましたか?

解決

Sounds like you simply don't want to add in the from x in gj.DefaultIfEmpty(), and you instead want to have each item in the left table paired with a group of items in the right table (that group may have zero elements, which is how you know when there are no matching items) which is exactly the behavior you get when you remove that line.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top