0

I have two Sql Server tables accessed through Entity Framework 4. They are joined by a single key with 0 to 1 rows on the dependent side of the join. Here is my linq query.

     var typeDtoList = from type in typeList
                       select (new DxStudioTypeDto(parent, 
                                                   isChildrenLoadOnDemand,
                                                   businessFacade,
                                                   server,
                                                   database,
                                                   type.typeGuid,
                                                   type.typeName,
                                                   type.writerName,
                                                   type.managerName,
                                                   type.Reporting_Type.MRef_Status,
                                                   type.Reporting_Type.Exists_In_Drop));

Obviously, if the Reporting_Type returns zero rows, the linq expression throws a null reference exception on the last two parameters of the DxStudioTypeDto constructor:

type.Reporting_Type.MRef_Status,
type.Reporting_Type.Exists_In_Drop));

Is there a way to detect the absence of a Reporting_Type row and substitute a default string? DxStudioTypeDto is an immutable type, so I need all the parameters available when I instanciate a new object. Any other strategies for this situation?

1 Answer 1

0

Did you try this?

((type.Reporting_Type == null) ? "some default value" : type.Reporting_Type.MRef_Status)

I know sometimes the EF engine returns a "the provider does not support this operation" for this kind of thing, but it's worth a try.

1
  • Sometimes the simplest things are the hardest to see. Thanks for the push in the right direction. Work well.
    – JimBoone
    Apr 8, 2012 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.