I believe that the problem that you see in your query is that by calling DefaultIfEmpty() you are trying to pull values ββfrom a null object. If you have a valid DeviceType but there are no DeviceParameters mapped, then when it tries to materialize the settings property with this statement:
settings = from s in g select new { ParamName = s.ParamName, Param1 = s.Param1, Param2 = s.Param2, Param3 = s.Param3 }
It tries to create a new object, and the object for "s" is null, so an attempt to access the parameter ParamName or Param1, etc. will not work. I tried the same code in LINQPad, and when I deleted the DefaultIfEmpty () call, everything worked.
Without knowing the properties and their types, I cannot be sure, but, as I said, based on the implementation of similar code in LINQPad, I got similar results.
Adam gritt
source share