Hi, I'm currently evaluating LLBL Gen Pro and have stumbled upon the following issue:
I'm doing this LINQ query:
from m in metaData.Messages
select new { Message = m }
which throws an exception:
Unhandled Exception: System.InvalidCastException: Unable to cast object of type
'System.Int32' to type 'XXX.EntityClasses.MessageEntity'.
bei lambda_method(ExecutionScope , Object[] , Int32[] )
bei SD.LLBLGen.Pro.LinqSupportClasses.DataProjectorToObjectList`1.AddRowToRes
ults(IList projectors, Object[] rawProjectionResult)
bei SD.LLBLGen.Pro.LinqSupportClasses.DataProjectorToObjectList`1.SD.LLBLGen.
Pro.ORMSupportClasses.IGeneralDataProjector.AddProjectionResultToContainer(List`
1 valueProjectors, Object[] rawProjectionResult)
bei SD.LLBLGen.Pro.ORMSupportClasses.ProjectionUtils.FetchProjectionFromReade
r(List`1 valueProjectors, IGeneralDataProjector projector, IDataReader datasourc
e, Int32 maxNumberOfItemsToReturn, Int32 pageNumber, Int32 pageSize, Boolean cli
entSideLimitation, Boolean clientSideDistinctFiltering, Boolean clientSidePaging
, UniqueList`1 stringCache, Dictionary`2 typeConvertersToRun)
bei SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetAsProjection(List`1 valueProj
ectors, IGeneralDataProjector projector, ITransaction transactionToUse, IRetriev
alQuery queryToExecute, Dictionary`2 typeConvertersToRun)
bei SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetAsProjection(List`1 valueProj
ectors, IGeneralDataProjector projector, ITransaction transactionToUse, IEntityF
ields fields, IPredicateExpression filter, IRelationCollection relations, Int32
maxNumberOfItemsToReturn, ISortExpression sortClauses, IGroupByCollection groupB
yClause, Boolean allowDuplicates, Int32 pageNumber, Int32 pageSize)
bei SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider.ExecuteValueListProj
ection(QueryExpression toExecute)
bei SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpressio
n(Expression handledExpression)
bei SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.Execute(Expressi
on expression)
bei SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQue
ryProvider.Execute(Expression expression)
bei SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.Execute()
bei SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.System.Collections.Ge
neric.IEnumerable<T>.GetEnumerator()
bei System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
bei System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
bei ConsoleApplication1.Program.Main(String[] args) in C:\...
When I do
from m in metaData.Messages
select new { Message = m.MessageId }
though, everything is fine. Is there something I'm missing or is the first query not supported?
The reason for doing this is that I would like to return a wrapper class that would contain a message plus the number of replies for that message, e.g.
from m in metaData.Messages
select new { Message = m, Count = (from c in m.Comments select c).Count() }
The Message-table is self-referencing with a nullable ParentMessageId.
BTW, I'm using SQL Server 2005.
Thanks.