Custom EntityField in typed list

Posts   
 
    
rock8613
User
Posts: 1
Joined: 07-Jun-2007
# Posted on: 25-Jul-2008 02:32:22   

I'm using LLBLGEN 2.5 Final

I need to return a full name from my typed list (concat of Last, first, middle). I have the list returning the empty column “Name”, but I’m not sure how to fill it with the concat of the 3 names.

// __LLBLGENPRO_USER_CODE_REGION_START AdditionalMembers private DataColumn _columnName; // __LLBLGENPRO_USER_CODE_REGION_END

// __LLBLGENPRO_USER_CODE_REGION_START AdditionalFields // be sure to call toReturn.Expand(number of new fields) first. toReturn.Expand(1); toReturn.DefineField(this.NameField, 16, "Name", "", AggregateFunction.None); // __LLBLGENPRO_USER_CODE_REGION_END

// __LLBLGENPRO_USER_CODE_REGION_START InitClass _columnName = new DataColumn("Name", typeof(System.String), null, MappingType.Element); _columnName.ReadOnly = true; _columnName.Caption = @"Name"; this.Columns.Add(_columnName); // __LLBLGENPRO_USER_CODE_REGION_END

// __LLBLGENPRO_USER_CODE_REGION_START InitMembers _columnName = this.Columns["Name"]; // __LLBLGENPRO_USER_CODE_REGION_END

// __LLBLGENPRO_USER_CODE_REGION_START CustomTypedListCode

Pseudocode – EntityField NameField = (EntityField)UserFields.LastName + UserFields.FirstName + UserFields.MiddleName;

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Jul-2008 07:53:52   

Hi rock8613, I would do that this way:

using System;
using System.ComponentModel;
using System.Data;
using System.Collections;

using Northwind.Model.EntityClasses;
using Northwind.Model.HelperClasses;
using Northwind.Model.FactoryClasses;

using SD.LLBLGen.Pro.ORMSupportClasses;

namespace Northwind.Model.TypedListClasses
{
    public partial class CustomerTypedList 
    {
        #region Class Member Declarations
        private DataColumn _columnFullName;
        #endregion
        
        
        /// <summary>
        /// Called when the typedlist's resultset has been build. This is the spot to add additional columns to the typedlist in code.
        /// We do this in code because we can't add a scalar query expression in the typedlist designer.
        /// </summary>
        /// <param name="fields">The typedlist resultset fields.</param>
        protected override void OnResultsetBuilt(IEntityFields2 fields)
        {
            // expand the fields with 1 slot, so we can add our scalar query expression to that slot
            int index = fields.Count;
            fields.Expand(1);
            // add a expression to the list of fields in the typedlist. The expression performs a
            // (CustomerTitle + " " + ContactName).
            fields.DefineField(new EntityField2("FullName", new Expression( 
                new Expression( CustomersFields.ContactTitle, ExOp.Add, " "), 
                ExOp.Add, CustomersFields.ContactName)), index);

            // done
            base.OnResultsetBuilt(fields);
        }

        /// <summary>
        /// Called when InitClass of the typedlist ended.
        /// </summary>
        protected override void OnInitialized()
        {
            _columnFullName = new DataColumn("FullName", typeof(string), null, MappingType.Element);
            _columnFullName.ReadOnly = true;
            this.Columns.Add(_columnFullName);
            base.OnInitialized();
        }


        #region Class Property Declarations
        /// <summary>
        /// Gets the FullName of the customer.
        /// </summary>
        /// <value>The FullName column.</value>
        internal DataColumn FullName
        {
            get { return _columnFullName; }
        }
        #endregion


    }

    public partial class CustomerRow
    {
        /// <summary>Gets / sets the value of the TypedList field FullName<br/><br/>
        /// </summary>
        /// <remarks>Mapped on: the expression for retrieving the (ContactTitle + " " + ContactName)</remarks>
        public string FullName
        {
            get
            {
                if (IsFullNameNull())
                {
                    return string.Empty;
                }
                else
                {
                    return (string)this[_parent.FullName];
                }
            }
        }

        /// <summary>Returns true if the TypedList field FullName is NULL, false otherwise.</summary>
        public bool IsFullNameNull()
        {
            return IsNull(_parent.FullName);
        }
    }

}

Here I use a partial class to be more clear, but with CODE_REGIONS should works as well. Above example works on my CustomerTypedList, so accommodate to your scenario and let us know if you need further help wink

David Elizondo | LLBLGen Support Team