Hi,
I have "wording" column which provides translate functionality. This column is nullable integer. I want to translate it "in-memory" (c# side).
This Linq query works fine
var q = from eventCat in md.EventCategory select Translate(eventCat.IdWordingIdentifier);
but this query (with anonymous constructor) does not
var q = from eventCat in md.EventCategory select new {A = Translate(eventCat.IdWordingIdentifier)};
it throws exception "Null object cannot be converted to a value type."
[InvalidCastException: Null object cannot be converted to a value type.]
System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) +7598766
System.Convert.ChangeType(Object value, Type conversionType) +32
lambda_method(ExecutionScope , Object[] , Int32[] ) +141
SD.LLBLGen.Pro.LinqSupportClasses.DataProjectorToObjectList1.AddRowToResults(IList projectors, Object[] rawProjectionResult) +104
SD.LLBLGen.Pro.LinqSupportClasses.DataProjectorToObjectList
1.SD.LLBLGen.Pro.ORMSupportClasses.IGeneralDataProjector.AddProjectionResultToContainer(List1 valueProjectors, Object[] rawProjectionResult) +9
SD.LLBLGen.Pro.ORMSupportClasses.ProjectionUtils.FetchProjectionFromReader(List
1 valueProjectors, IGeneralDataProjector projector, IDataReader datasource, Int32 maxNumberOfItemsToReturn, Int32 pageNumber, Int32 pageSize, Boolean clientSideLimitation, Boolean clientSideDistinctFiltering, Boolean clientSidePaging, UniqueList1 stringCache, Dictionary
2 typeConvertersToRun) +1220
SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetAsProjection(List1 valueProjectors, IGeneralDataProjector projector, ITransaction transactionToUse, IRetrievalQuery queryToExecute, Dictionary
2 typeConvertersToRun) +127
SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetAsProjection(List1 valueProjectors, IGeneralDataProjector projector, ITransaction transactionToUse, IEntityFields fields, IPredicateExpression filter, IRelationCollection relations, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IGroupByCollection groupByClause, Boolean allowDuplicates, Int32 pageNumber, Int32 pageSize) +248
SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider.ExecuteValueListProjection(QueryExpression toExecute) +234
SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpression(Expression handledExpression) +183
SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.Execute(Expression expression) +23
SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute(Expression expression) +17
SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery
1.Execute() +16
SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +16
System.Collections.Generic.List
1..ctor(IEnumerable1 collection) +7665318
System.Linq.Enumerable.ToList(IEnumerable
1 source) +61
...
Translate method
private string Translate(int id)
{
return "aa";
}
It works fine if none of IDs in database is null.
I roughly understand why it does not work. The question is how to make it work