Combining Entity Fields for Display

Posts   
 
    
Valkiri
User
Posts: 5
Joined: 21-Nov-2008
# Posted on: 21-Nov-2008 02:36:58   

Hi to one and all, This question has probably been asked before but despite searching for previous threads I have been unable to find a solution. I'm using V2.6 and VS2008. Self servicing project and in this instance utilising an existing Access dB.

I want to fill a combobox that displays a combination of 2 fields from the table such as : entity field 1 : firstname entity field 2 : lastname entity field 3 : personID

and I want to combine fields 1 & 2 for display/user choice purposes, as part of a cascading selection criteria e.g.

firstname + lastname as fullname cbo.displaymember = fullname cbo.valuemember = personID

Can anyone point me to a previous thread or provide a new solution to amend/add to the generated code for PersonEntity that achieves the above.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 21-Nov-2008 04:28:28   

The best way is to add a custom property to your PersonEntity. You can do that at PersonEntity.cs:

// __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode
public string FullName
{
     get
     {
          return FirstName + " " + LastName;
     }
}
// __LLBLGENPRO_USER_CODE_REGION_END

Or, at a partial class:

using System;
using SD.LLBLGen.Pro.ORMSupportClasses;

namespace Northwind.Model.EntityClasses
{
    public partial class CustomersEntity
    {
        public string FullName
        {
            get
            {
                return FirstName + " " + LastName;
            }
        }
    }
}

Then you should be able to use that custom property at databind:

cbo.displaymember = "FullName";
David Elizondo | LLBLGen Support Team
Valkiri
User
Posts: 5
Joined: 21-Nov-2008
# Posted on: 21-Nov-2008 10:55:02   

Many thanks daelmo.

Perfect. Solutions seem so obvious once your on the inside track and totally opaque otherwise. I was really racking my brain reading over and over the how to.. and especially galling as intuitively I knew the answer was simple.confused

With this simple workflow I now feel more empowered as this will be the seed for many other code customizations.

Once again thanks for the speedy answer.smile