Related entity collection of derived class & prefetch path

Posts   
 
    
pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 07-Aug-2007 20:56:52   
// Code is generated using LLBLGen Pro version: 2.0.0.0
// Code is generated using templates: SD.TemplateBindings.SharedTemplates.NET20
// Database used is SQL Server 2005
// Template: adapter two classes

Ok. I have "Task" table with a one to many relationship to "TaskVersions".

In code I fetch a MyTaskEntity with a prefetch path for TaskVersions. Then when I access TaskVersionCollection in MyTaskEntity I get a EntityCollection<TaskVersionEntity> instead of EntityCollection<MyTaskVersionEntity>.

        /// <summary>
        /// Gets the EntityCollection with the related entities of type 'MyTaskVersionEntity' which are related to this entity via a relation of type '1:n'.
        /// If the EntityCollection hasn't been fetched yet, the collection returned will be empty.
        /// </summary>
        [TypeContainedAttribute(typeof(MyTaskVersionEntity))]
        public override EntityCollection<TaskVersionEntity> TaskVersionCollection
        {
            get
            {
                EntityCollection<TaskVersionEntity> toReturn = base.TaskVersionCollection;
                toReturn.EntityFactoryToUse = new MyTaskVersionEntityFactory();
                return toReturn;
            }
        }

But I found the reason for this now so this thread is just in case some body else has a similar challenge.

My prefetch path was wrong: I had:

            PrefetchPath2 prefetch = new PrefetchPath2((int)EntityType.TaskEntity);
            prefetch.Add(TaskEntity.PrefetchPathTaskVersionCollection);

which returns a collection of TaskVersionEntity for the TaskVersionCollection property

instead of:

            PrefetchPath2 prefetch = new PrefetchPath2((int)EntityType.TaskEntity);
            prefetch.Add(MyTaskEntity.PrefetchPathTaskVersionCollection);

which returns a collection of MyTaskVersionEntity for the TaskVersionCollection property

Hope it helps someone Patrick

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 07-Aug-2007 21:49:32   

Thanks for sharing this solution! simple_smile

Frans Bouma | Lead developer LLBLGen Pro