views:

105

answers:

0

I apologize in advance for not being able to give a code sample. It would be problematic and not quite clear but the pseudo below may suffice.

What I'm attempting to do is construct a dynamic projection leveraging system.linq.dynamic. I'm, at times, asking LinqToSql to do some magic and asking for properties in a related entity by using a FullyQualified name.

public class Entity1
{
   public int ID {get;set;}
   public Entity2 SecondEntity {get;set;}
}

public class Entity2
{
   public int ID {get; set;}
   public int ValueTypeProperty;
}

My dynamic select projection then looks something like this (pseudo) :

" new(ID, SecondEntity.ValueTypeProperty) "

LinqToSql builds me a LeftOuterJoin between the two tables under the hood. The problem is that when Entity2 is null LinqToSql throws the exception "The null value cannot be assigned to a member with type which is a non-nullable value type".

Obviously, I'm having trouble devising a work-around.

Thanks.