Fetching against base class.

Posts   
 
    
mwightman
User
Posts: 7
Joined: 31-Mar-2009
# Posted on: 31-Mar-2009 18:29:39   

I am attempting to fetch a subclass entity by a unique key, UserEnity is an abstract base for Member and NonMember. I would expect this code to return an instance of a concrete type down cast to a UserEntity. If I use the concrete class as the prototype it works.


        public UserEntity Find(string external_id)
        {
            IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.MailboxEntity);
            prefetchPath.Add(UserEntity.PrefetchPathMailbox);

            //User is abstract base for Member and NonMember
            UserEntityFactory uFactory=new UserEntityFactory();
            UserEntity u=(UserEntity)uFactory.Create();
            u.ExternalId=external_id;

            //Search by unique id
            IPredicateExpression p = u.ConstructFilterForUCTypeExternalId();

            IDataAccessAdapter adapter = base.GetDataAccessAdapter();
            bool userFound = adapter.FetchEntityUsingUniqueConstraint(u, p, prefetchPath);

            if (userFound)
            {
                if (u is MemberEntity)
                {
                    this.FillMemeberExtendedData((MemberEntity )u);
                    u.IsDirty = false;
                }
                return u;
            }
            else 
            {
                return null;
            }
        
        }



daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 01-Apr-2009 04:27:21   

What exactly doesn't work on your code? LLBLGen Pro version and runtime library version? (http://llblgen.com/tinyforum/Messages.aspx?ThreadID=7722)

IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.MailboxEntity);
prefetchPath.Add(UserEntity.PrefetchPathMailbox);

Another question: Is this working? As I see you aren't using the UserEntity (the one you are fetching) as the root element of the prefetchPath.

David Elizondo | LLBLGen Support Team