Is is possible to add to add to ConstantsEnums.vb

Posts   
 
    
like2175
User
Posts: 83
Joined: 27-Mar-2006
# Posted on: 29-Apr-2009 10:07:31   

I have a PersonEntity with FirstName MiddleName and SurnameName but I often need to display the full name, so in PersonEntity I've created

 Public ReadOnly Property FullName() As String
      Get
        Return Me.FirstName & Replace(" " & Me.MiddleName & " ", "  ", " ") & Me.Surname
      End Get
    End Property

when filtering/sorting I reference Surname using PersonFields.Surname like:

Dim sorter As New SortExpression(PersonFields.Surname Or SortOrder.Ascending)

What I'd really like to be able to do us reference the FullName in a similar way:

Dim sorter As New SortExpression(PersonFields.FullName Or SortOrder.Ascending)

Is there anyway to get 'FullName' to be added to the ConstantsEnums.vb file during generation so that PersonFields.FullName works? Is this a template thing?

This would be particularly helpful as I'm having trouble getting this to work:

 'fields.DefineField(New EntityField("FullName", PersonFields.FirstName + " "+ PersonFields.Surname), 2, "FullName")

in

  Dim fields As New ResultsetFields(3)
    fields.DefineField(TripStopPersonActivityFields.PersonId, 0)
    fields.DefineField(TripStopPersonActivityFields.PersonActivityTypeId, 1, "OnOffBoard", AggregateFunction.Sum)
    'fields.DefineField(New EntityField("FullName", PersonFields.FirstName + PersonFields.Surname), 2, "FullName")
    fields.DefineField(PersonFields.Surname, 2)
    Dim relations As IRelationCollection = New RelationCollection()
    relations.Add(TripStopPersonActivityEntity.Relations.TripStopEntityUsingTripStopId)
    relations.Add(TripStopPersonActivityEntity.Relations.PersonEntityUsingPersonId)

    Dim groupByClause As IGroupByCollection = New GroupByCollection()
    groupByClause.Add(fields(0))
    groupByClause.Add(fields(2))

    groupByClause.HavingClause = New PredicateExpression( _
     fields(1).SetExpression(TripStopPersonActivityFields.PersonActivityTypeId * 1).SetAggregateFunction(AggregateFunction.Sum) = 1)



    Dim filter As IPredicateExpression = ((TripStopFields.LocationId = locationId) And _
          (TripStopFields.StatusId <> StatusEntity.Deleted) And _
          (TripStopFields.Etd <= etd))

    Dim dynamicList As New DataTable()
    Dim dao As New TypedListDAO()
    dao.GetMultiAsDataTable(fields, dynamicList, 0, Nothing, filter, relations, True, groupByClause, Nothing, 0, 0)

whereas I can see that

fields.DefineField(PersonFields.Fullname, 2)

would work

Any help gratefully received.

vb.net 2008, winforms, self-serve, llblgenpro v2.6.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 29-Apr-2009 10:24:28   

PersonFields is the enum of fields mapped to database columns.

If you want to add FullName as an extra property to the entity, then you should know that filtering and sorting on this property would be done at client side not on the database side.

Otherwise you should have added a computed column in the database and refresh the catalog from the designer to include this clumn in the generated code.

Using an EntityView you can filter a collection as follows:

IPredicateExpression filter = new PredicateExpression();
filter.AddWithAnd(new EntityProperty("FullName") == "George Clooney");
customerView.Filter = filter;
like2175
User
Posts: 83
Joined: 27-Mar-2006
# Posted on: 29-Apr-2009 17:03:44   

Walaa, thanks for your pointer:

I've added a FullName field to the database, which, because the db is Access 97 (with no triggers!) , I populate though an OnSave method on my PersonEntity

' __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode

    Protected Overrides Sub OnSave()
    
      Me.FullName = Me.FirstName & Replace(" " & Me.MiddleName & " ", "  ", " ") & Me.Surname
      MyBase.OnSave()

    End Sub

    ' __LLBLGENPRO_USER_CODE_REGION_END