Custom TypedView Code

Posts   
 
    
DaveR
User
Posts: 43
Joined: 15-Jun-2004
# Posted on: 08-Nov-2005 22:40:15   

Are custom code regions in TypedView classes supported?

We're trying to add code in the usual way, i.e.

but when we regenerate the code, these regions are overridden.

#region Custom TypedRow code
// __LLBLGENPRO_USER_CODE_REGION_START CustomTypedRowCode
// __LLBLGENPRO_USER_CODE_REGION_END        
#endregion

Using Version 1.0.2004.2 July 25th, 2005.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 08-Nov-2005 23:03:08   

You added code to a region in the generated code or did you add the region as well to the generated code?

Frans Bouma | Lead developer LLBLGen Pro
DaveR
User
Posts: 43
Joined: 15-Jun-2004
# Posted on: 09-Nov-2005 00:14:27   

We added a new #region to the code, outside of existing regions, following the example of the entity classes.

We tried different permutations, i.e. putting inside existing region, outside any region, but the custom code is always overwritten.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 09-Nov-2005 10:08:31   

You can't add a region into the code, that's not how it works. The template engine sees a region definition in the template, then reads the region from the code file that already exists, and merges that into the output generated at the spot of the region read in the template (so you can have scoped regions). So if you add a region to the generated code, that's not helping.

You should add the region to the generated code by adding a usercoderegion definition to an include template, then bind that template to the include template ID for typed views. The usercode region then will end up in the template, and it will thus work. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
pg
User
Posts: 13
Joined: 19-Oct-2005
# Posted on: 11-Nov-2005 16:00:51   

But why isn't there already any custom code region in typed views, as it is for example in entity and collection classes?

Since "Custom Code Regions" are very usefull in Entities and Collections, I was wondering if it is going to be added in typed Views in a future realease.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 12-Nov-2005 18:00:27   

Which regions do you want us to add and to which classes/routines precisely? I'd prefer if you also state an example for the region usage. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
pg
User
Posts: 13
Joined: 19-Oct-2005
# Posted on: 13-Nov-2005 13:22:03   

We want to add custom made columns to a view. For example, lets say that we have a view that returns a patient's First Name, Last Name and Middle Name and we want to have extra columns based on those three like: FullNameInverse, FullName, ShortName and ShortNameInverse.

It would be much more flexible to be able to add this columns in the typedRow class instead of trying to build the column using SQL directly in the Database View.

For example the following whould be very usefull in a TypedRow class:

// __LLBLGENPRO_USER_CODE_REGION_START CustomTypedRowCode

public string PatientNameInverse { get { if (0 == this.PatientLastName.Length && 0 == this.PatientFirstName.Length && 0 == this.PatientMiddleName.Length) return "";

            return string.Format("{0}, {1} {2}", this.PatientLastName, this.PatientFirstName, this.PatientMiddleName).Trim();
        }
    }

and

public string PatientName { get { if (this.PatientMiddleName.Length > 0) return string.Format("{0} {1} {2}", this.PatientFirstName, this.PatientMiddleName, this.PatientLastName).Trim(); else return string.Format("{0} {1}", this.PatientFirstName, this.PatientLastName).Trim(); } }

// __LLBLGENPRO_USER_CODE_REGION_END

Then in typed views we might need to add custom fill methods that use specific criteria. Lets say that we have a view that returns medical reports and we want to build a custom method that would return draft reports. We want to put that method in the typedView class because we use it in different parts of our application.

The folowing would be usefull:

// __LLBLGENPRO_USER_CODE_REGION_START CustomTypedViewCode

public bool GetReportsDrafts(int siteID, int accountID, Role userRole, int rowsToReturn, ISortExpression sortClauses) { IPredicateExpression selectFilter = BuildReportsDraftsFilter(accountID, userRole, siteID); return Fill(rowsToReturn, sortClauses, true, selectFilter); }

......

private IPredicateExpression BuildReportsDraftsFilter(int accountID, Role userRole, int siteID) {

        IPredicateExpression filter = new PredicateExpression(PredicateFactory.CompareValue(ExplorerFieldIndex.ReportStatus, ComparisonOperator.Equal, ReportStatus.Draft));

.......

        return filter;
    }

// __LLBLGENPRO_USER_CODE_REGION_END

Collections already support this functionallity. Why not TypedViews as well?

What we do now is, add this custom code regions in TYpedView and TypedViewRow and do the merge manually after code regeneration disappointed

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 13-Nov-2005 14:48:10   

So basicly that's the same as the regions found in a typed list. Be aware that to be able to use new properties best, it's key datacolumns are added to teh underlying datatable. The typedlist already has regions for doing so in buildresultset.

For the code in the CustomTypedViewCode region you posted, you can use an include template, which generates a usercoderegion in every typed view. You can then add the code to that usercoderegion, or you can also generate the code you want to add to the view via the include template (for example, if the code is used in every typedview).

I'll update the typedview template with regions ala the typedlist, (and also the row classes so they're extensible as well).

Frans Bouma | Lead developer LLBLGen Pro
Rogelio
User
Posts: 221
Joined: 29-Mar-2005
# Posted on: 13-Nov-2005 15:08:38   

Hi,

About adding custom code (that return typedview) inside the typedview class, be aware that this approach will not work if you decide to use your app. with a remote-business server that will supply service to your GUI tier. It is better to have a class service that has method to return the typedview with the data that you need.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 15-Nov-2005 12:45:20   

These regions have been added to the template, and are available in the next build.

Frans Bouma | Lead developer LLBLGen Pro