Error on FetchEntityCollection

Posts   
 
    
peschkaj
User
Posts: 30
Joined: 21-Sep-2006
# Posted on: 09-Oct-2006 17:52:41   

When I attempt to pull any EntityCollection from the database, I get a System.ArgumentException:

An exception of type 'System.ArgumentException' occurred in SD.LLBLGen.Pro.ORMSupportClasses.NET20.DLL but was not handled in user code

Additional information: entityToAdd isn't of the right type

Stack Trace: [ArgumentException: entityToAdd isn't of the right type]

SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase2`1.SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection2.Add(IEntity2 entityToAdd) +135
   SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.ExecuteMultiRowRetrievalQuery(IRetrievalQuery queryToExecute, IEntityFactory2 entityFactory, IEntityCollection2 collectionToFill, IFieldPersistenceInfo[] fieldsPersistenceInfo, Boolean allowDuplicates, IEntityFields2 fieldsUsedForQuery) +2565
   SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollectionInternal(IEntityCollection2 collectionToFill, IRelationPredicateBucket& filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Int32 pageNumber, Int32 pageSize) +820
   SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Int32 pageNumber, Int32 pageSize) +187
   SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket) +43
   CareWorksTechnologies.WatchDog.Account_UserManagement.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\Jeremiah Peschka\My Documents\Visual Studio 2005\Projects\WatchDog\WatchDog30_WAP\Account\UserManagement.aspx.cs:31
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +31
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +68
   System.Web.UI.Control.OnLoad(EventArgs e) +88
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3036

This is the code in question.


EntityCollection<MyUserEntity> _users = new EntityCollection<MyUserEntity>();
EntityCollection<MyProjectEntity> _projects = new EntityCollection<MyProjectEntity> ();
MyUserEntity _currentUser = Utility.CurrentUser ();

using (DataAccessAdapter _adapter = Utility.GenerateDataAccessAdapter ())
{
    _adapter.FetchEntityCollection (_users, null); // Exception thrown here
    _adapter.FetchEntityCollection (_projects, _currentUser.GetRelationInfoProjectCollectionViaProjectUser());
}

If I change the entity from MyUserEntity to UserEntity, everything works correctly.

Thanks,

Jeremiah Peschka

LLBLGen Pro version 2.0.0.0 Final SQL Server 2005

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 09-Oct-2006 18:28:04   

Could you try: EntityCollection<MyUserEntity> _users = new EntityCollection<MyUserEntity>(new MyUserEntityFactory());

Frans Bouma | Lead developer LLBLGen Pro
peschkaj
User
Posts: 30
Joined: 21-Sep-2006
# Posted on: 09-Oct-2006 19:35:09   

Thank you, that worked!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 10-Oct-2006 11:34:36   

Your code revealed a small bug in the derivedentity template. I'll correct that in the next build.

Frans Bouma | Lead developer LLBLGen Pro