1

Is it possible to do:

IEnumerable<MyModel> models = context.MyDBModels
                .Include(x => x.ConnectionA)
                .Select(x => new MyModel{        
                    SomeData = new SomeDataClass 
                    {
                        prop1 = x.ConnectionA.ConnectionB.prop1,
                        prop2 = x.ConnectionA.ConnectionB.prop2,
                    }
                });

when ConnectionB for example is null since null propagating operator is not possible in tree expressions like these.

I tested it and it looks like it works (it doesn't throw exceptions and in prop1/prop2 I have null as I want), but I want to be sure

sgch
  • 77
  • 1
  • 7

1 Answers1

0

When using LINQ to databases, the LINQ is translated to SQL (or other database query language) and the handling of null depends on that language. In the case of SQL, null propagation is essentially automatic, though you have to be aware if you switch to client side processing somewhere in the LINQ query.

NetMage
  • 26,163
  • 3
  • 34
  • 55