When I attempt to fill an EntityCollection with a polymorphic entity 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
The error message is: entityToAdd isn't of the right type.
EntityCollection<Contract> list = new EntityCollection<Contract>(new ContractFactory());
Contract addNew = list.AddNew();
_daa.FetchEntityCollection(list, null);
ContractFactory looks like this:
public class ContractFactory : LeaseContractEntityFactory
{
public override IEntity2 Create()
{
return new Contract();
}
public override IEntity2 Create(IEntityFields2 fields)
{
return new Contract(fields);
}
}
"Contract" is a custom class that inherits from "LeaseContractEntity", and "LeaseContractEntity" is a generated class that inherits from "ContractEntity".
I've added a partial class with ExecuteMultiRowRetrievalQuery to DataAccessAdapter, and the error occurs here:
public partial class DataAccessAdapter : DataAccessAdapterBase
{
public override void ExecuteMultiRowRetrievalQuery(IRetrievalQuery queryToExecute, IEntityFactory2 entityFactory, IEntityCollection2 collectionToFill, IFieldPersistenceInfo[] fieldsPersistenceInfo, bool allowDuplicates, IEntityFields2 fieldsUsedForQuery)
{
base.ExecuteMultiRowRetrievalQuery(queryToExecute, entityFactory, collectionToFill, fieldsPersistenceInfo, allowDuplicates, fieldsUsedForQuery);
}
}
Any ideas?