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

2
  • 1
    It should work, even better, you can remove Include, it is not needed when you have custom projection. Commented Dec 31, 2020 at 14:07
  • Oh, ok great!, thanks! Commented Dec 31, 2020 at 14:17

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.