I’m trying to populate a dictionary using a nested select, and I get nullreference exception, since objects from TableC might not exists.
List<SomeResult> test = (from a in _entities.TableA
select new SomeResult
{
TestB = a.TableB.Name,
TestCDict = a.TableC.ToDictionary(x => x.SomeKey, x => x.SomeValue)
}).ToList();
How do I fix so TestCDict can be null?
/Lasse
Change it to this:
Or to this, if you want an empty dictionary instead of null in
TestCDict: