Unable to cast object when trying to use a projection

Posts   
 
    
cds avatar
cds
User
Posts: 20
Joined: 01-Feb-2006
# Posted on: 19-Mar-2009 22:27:58   

Hi

I'm trying out LINQ to LLBLGen and have this code which compiles but gets a runtime error.

using (var adapter = new DataAccessAdapter()) { LinqMetaData metaData = new LinqMetaData(adapter); var statusSelections = (from s in metaData.Status where s.IsValid == 1 select new StatusSelection(s)).ToList(); }

The StatusSelection class is defined with a constructor taking a StatusEntity object.

I get this exception:

System.InvalidCastException: Unable to cast object of type 'System.Guid' to type 'XXXX.XXXX.DataAccess.EntityClasses.StatusEntity'. at lambda_method(ExecutionScope , Object[] , Int32[] ) at SD.LLBLGen.Pro.LinqSupportClasses.DataProjectorToObjectList1.AddRowToResults(IList projectors, Object[] rawProjectionResult) at SD.LLBLGen.Pro.LinqSupportClasses.DataProjectorToObjectList1.SD.LLBLGen.Pro. ORMSupportClasses.IGeneralDataProjector.AddProjectionResultToContainer(List1 valueProjectors, Object[] rawProjectionResult) at SD.LLBLGen.Pro.ORMSupportClasses.ProjectionUtils.FetchProjectionFromReader(List1 valueProjectors, IGeneralDataProjector projector, IDataReader datasource, Int32 maxNumberOfItemsToReturn, Int32 pageNumber, Int32 pageSize, Boolean clientSideLimitation, Boolean clientSideDistinctFiltering, Boolean clientSidePaging, UniqueList1 stringCache, Dictionary2 typeConvertersToRun) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchProjection(List1 valueProjectors, IGeneralDataProjector projector, IRetrievalQuery queryToExecute, Dictionary2 typeConvertersToRun) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchProjection(List1 valueProjectors, IGeneralDataProjector projector, IEntityFields2 fields, IRelationPredicateBucket filter, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IGroupByCollection groupByClause, Boolean allowDuplicates, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider2.ExecuteValueListProjection(QueryExpression toExecute) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpression(Expression handledExpression) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.Execute(Expression expression) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute(Expression expression) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery1.Execute() at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)

This is running on version 2.6, latest build dated 9 March 2009.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 20-Mar-2009 05:56:19   

Please post the StatusSelection method's code.

Anyway, this is related to: http://llblgen.com/tinyforum/Messages.aspx?ThreadID=15133 http://llblgen.com/tinyforum/Messages.aspx?ThreadID=14390

David Elizondo | LLBLGen Support Team
cds avatar
cds
User
Posts: 20
Joined: 01-Feb-2006
# Posted on: 20-Mar-2009 10:40:15   

OK, thanks for that. I understand what's going on now from those threads.

It's a little inconvenient though... disappointed but I can see that it's not supported. It would be nice if there was some way to force the entity to be materialised so that i could pass it into a method. I really do want to store a reference to it, I think. confused

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 20-Mar-2009 19:46:36   

I recommend you read this section of the manual and post your In-Memory function. Maybe there exist a workaround for this.

David Elizondo | LLBLGen Support Team