Entities inheritance

Posts   
 
    
ggpnet
User
Posts: 21
Joined: 07-Apr-2005
# Posted on: 30-Sep-2007 20:00:03   

VS.2005 Pro Edition LLBLGen 2.5 Build 09.24.2007 Firebird 2.0.1 FirebirdClient 2.0.1.0

I have the SomeEntity generated by LLBLGen.

This is the SomeEntityFactory Extended

using SomeDAL.FactoryClasses;
using SomeDAL.HelperClasses;

namespace SomeDAL.FactoryClasses
{
    [Serializable]
    public class SomeEntityFactoryExt : SomeEntityFactory
    {           
        private readonly SomeEnum enumValue;
        
        public SomeEntityFactoryExt()
        {
            enumValue = SomeEnum.Default;
        }

        public SomeEntityFactoryExt(SomeEnum pmrEnumValue)
        {
            enumValue = pmrEnumValue;
        }

        public override IEntity2 Create(IEntityFields2 fields)
        {
            return new SomeEntityInherited(fields);
        }

        public override string ForEntityName
        {
            get
            {
                return "SomeEntityInherited";
            }
        }

        public override IEntityFields2 CreateFields()
        {
             Add new fields..........which calculation is based on the enumValue.......
         }
    }       
}

This is the inherited Entity

namespace SomeDAL.EntityClasses
{
    [Serializable]
    public class SomeEntityInherited : SomeEntity
    {               
        public SomeEntityInherited(string someValue) : base(sameValue) {}
        
        public SomeEntityInherited(IEntityFields2 fields) : base(fields) {}
        
        public SomeEntityInherited() {}
    
        protected override IEntityFactory2 CreateEntityFactory()
        {
            return new SomeEntityFactoryExt();      
        }
        
            Public Properties for the new Fields..........................
        
    }
}

This is how I fetch the inherited Entity and the only way I can fetch it.

IRelationPredicateBucket relPredBucket = new RelationPredicateBucket(SomeFields.Year == "2007");
DataAccessAdapter adapter = new DataAccessAdapter();            
SomeEntityInherited entSomeInherited = adapter.FetchNewEntity<SomeEntityInherited>   (relPredBucket);

Because these don't work, there aren't exceptions but don't fetch the new Fields.

SomeEntityInherited entSomeInherited = new SomeEntityInherited("2007");
adapter.FetchEntity(entSomeInherited)

nor

IRelationPredicateBucket relPredBucket = new RelationPredicateBucket(SomeFields.Year == "2007");
SomeEntityInherited entSomeInherited = new SomeEntityInherited();
adapter.FetchEntityUsingUniqueConstraint(entSomeInherited, relPredBucket);

I'm not sure if this is the correct way to do it or if I'm missing something or I'm doing something wrong.

Any help will be much appreciated.

Kind Regards Gianfranco

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 01-Oct-2007 01:02:39   

Hi Gianfranco, I think this method is missing at your _SomeEntityInherited _class:

protected override IEntityFields2 CreateFields()
{
    return new SomeEntityFactoryExt().CreateFields();           
}

Otherwise the base CreateFields() is used (that doesn't contain your new fields definition).

Regards

David Elizondo | LLBLGen Support Team
ggpnet
User
Posts: 21
Joined: 07-Apr-2005
# Posted on: 01-Oct-2007 01:36:38   

You're right, now everything works OK.

Thanks David.

Gracias hermano.

Saludos Gianfranco