Create custom contructors for entity?

Posts   
 
    
kkemp
User
Posts: 23
Joined: 21-Sep-2003
# Posted on: 11-Jan-2009 00:21:09   

Is it possible to create your own custom contructors for the entity objects? I couldn't find any examples of this being done on the forums/etc.

An example of what I have in mind is done with this code in my partial class, except it results in two database calls and I'm not really sure if I even should be calling InitClassFetch myself.


public EplanReportSectionInstanceEntity(long entityId, long reportInstanceId, Enums.ReportSectionIds reportSectionId)
        {
            EplanReportSectionInstanceCollection reportSectionInstances = new EplanReportSectionInstanceCollection();

            IPredicateExpression filter = new PredicateExpression(EplanReportSectionInstanceFields.EntityId == entityId);

            filter.AddWithAnd(EplanReportSectionInstanceFields.EplanReportInstanceId == reportInstanceId);
            filter.AddWithAnd(EplanReportSectionInstanceFields.EplanReportSectionId == reportSectionId);

            reportSectionInstances.GetMulti(filter);

            if (reportSectionInstances.Count == 0)
            {
                return;
            }

            InitClassFetch(reportSectionInstances[0].EplanReportSectionInstanceId, null, null);
}

-Keith

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Jan-2009 18:29:03   

You can try this, to avoid the extra fetch:

public EplanReportSectionInstanceEntity(long entityId, long reportInstanceId, Enums.ReportSectionIds reportSectionId)
        {

            InitClassEmpty(null);

            EplanReportSectionInstanceCollection reportSectionInstances = new EplanReportSectionInstanceCollection();

            IPredicateExpression filter = new PredicateExpression(EplanReportSectionInstanceFields.EntityId == entityId);

            filter.AddWithAnd(EplanReportSectionInstanceFields.EplanReportInstanceId == reportInstanceId);
            filter.AddWithAnd(EplanReportSectionInstanceFields.EplanReportSectionId == reportSectionId);

            reportSectionInstances.GetMulti(filter);

            if (reportSectionInstances.Count == 0)
            {
                return;
            }

            this.Fields = reportSectionInstances[0].Fields.Clone();
            this.IsNew = false;
}
David Elizondo | LLBLGen Support Team