Brian Ogden
Brian Ogden

Reputation: 19212

Having trouble with a Linq Join statement

So I have the following Linq query:

var comb1 = (from m1 in _modified
                     join o1 in _original on m1.custom_field_option_id equals o1.custom_field_option_id
                     from e1 in _existing
                     .Where(row => (m1.custom_field_option_id == row.custom_field_option_id || m1.custom_field_option_id == 0)
                         && row.custom_field_id == m1.custom_field_id).DefaultIfEmpty()
                     select new { m1, o1, e1 }).ToArray();

In List _modifed I have two items. In List _original I have one item. The second item in _modified is a new insert record. _original does not contain this record and nor does _existing.

The new record is not being included in my combined array. The custom_field_option_id of the new record is currently 0 so I added to my where clause:

|| m1.custom_field_option_id == 0

But that didn't help.

How do I change this query to include the new record in _modified?

Upvotes: 0

Views: 70

Answers (1)

user3097514
user3097514

Reputation: 359

unless i am missing sommething: join o1 in _original on m1.custom_field_option_id equals o1.custom_field_option_id is a hard join to whatever is in _original.

Could it be that the row is not present because the row is not in _original?

Upvotes: 1

Related Questions