Hello,
I have a Customer class with an Image field which is a nullable byte[].
When doing this query:
var xx = _db.Customers.Select(p => new
{
Id = p.Id,
Name = p.Name,
Image = p.Image
}).ToList();
I got the following exception:
System.InvalidCastException was unhandled by user code
HResult=-2147467262
Message=Invalid cast from 'System.DBNull' to 'System.Byte[]'.
Source=mscorlib
StackTrace:
at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
at System.DBNull.System.IConvertible.ToType(Type type, IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at Mindscape.LightSpeed.Linq.Utils.TypeHelper.NonNullableConvert(LightSpeedContext context, Object value, Type targetType)
at Mindscape.LightSpeed.Linq.Utils.TypeHelper.NullableSafeConvert(LightSpeedContext context, Object value, Type targetType)
at Mindscape.LightSpeed.Linq.ProjectedTypeBuilder.GetValue(Int32 expressionIndex, IDataRecord record, Type targetType)
at Mindscape.LightSpeed.Linq.ProjectedTypeBuilder.CreateInstanceFromReader(NewExpression newExpression, IDataRecord record)
at Mindscape.LightSpeed.Linq.AnonymousTypeBuilder.Build(LightSpeedContext context, IDataRecord record)
at Mindscape.LightSpeed.Linq.Plan.SingleQueryPlan.ExecuteProjectNativeCore(IUnitOfWork unitOfWork, IProjectionBuilder builder)
at Mindscape.LightSpeed.Linq.Plan.SingleQueryPlan.DispatchProjectNative[T](IUnitOfWork unitOfWork, Func`3 builderFunc)
at Mindscape.LightSpeed.Linq.Plan.SingleQueryPlan.ExecuteProjectNative(IUnitOfWork unitOfWork)
at Mindscape.LightSpeed.Linq.Plan.SingleQueryPlan.<>c__DisplayClass1d.<ExecuteProject>b__1b()
at Mindscape.LightSpeed.Linq.Plan.SingleQueryPlan.ChooseProjectImplementation[T](Func`1 native, Func`1 clientSide)
at Mindscape.LightSpeed.Linq.Plan.SingleQueryPlan.ExecuteProject(IUnitOfWork unitOfWork)
at Mindscape.LightSpeed.Linq.Plan.SingleQueryPlan.ExecuteImmediate(IUnitOfWork unitOfWork, Type returnType)
at Mindscape.LightSpeed.Linq.LinqQueryProvider.Execute(Expression expression)
at Mindscape.LightSpeed.Linq.LinqQueryProvider.System.Linq.IQueryProvider.Execute(Expression expression)
at Mindscape.LightSpeed.Linq.LinqQuery`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)