Custom Field Property

Posts   
 
    
c_pousson
User
Posts: 12
Joined: 03-Jul-2008
# Posted on: 25-Jul-2008 18:14:05   

Hi, I have an entity called person. In the entity class I have made a property that is called FullName get{this.Lastname + ", " + this.FirstName}

and I was wondering how I could make this available in the fields collection

meaning: I can access things like this

IEntityCollection2 inCollection; inCollection[0].Fields["FirstName"]

but I would like to be able to access the FullName in this manner so inCollection[0].Fields["FullName"]

Is there a way to accomplish this?

Thanks in advanced

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Jul-2008 20:27:12   

Take a look at the step 6 of this Frans Bouma's article.

David Elizondo | LLBLGen Support Team
c_pousson
User
Posts: 12
Joined: 03-Jul-2008
# Posted on: 25-Jul-2008 21:22:09   

Thanks, that works perfectly but I need advice on a small issue

my expression for the field looks like this:

IEntityField2 fullNameField = new EntityField2("FullName", new Expression(Person.LastName,ExOp.Add,Person.FirstName));

that works but it returns SchmoeJoe I need the expression to return Schmoe, Joe. How do I achieve this.

sorry, I am new to the expressions code

also, we are regenerating code a lot. how do I stop the new code from being deleted on a regen


public virtual IEntityFields2 CreateFields()
        {
            //__LLBLGENPRO_USER_CODE_REGION_START
            IEntityFields2 fieldsToReturn = EntityFieldsFactory.CreateEntityFieldsObject(HOO.LARS.BLL.EntityType.person);
            fieldsToReturn.Expand(1);
            IEntityField2 fullNameField = new EntityField2("FullName",
                    new Expression(personfields.LastName,ExOp.Add,personFields.FirstName));
            fieldsToReturn.DefineField(fullNameField, fieldsToReturn.Count - 1);
            return fieldsToReturn;
            // __LLBLGENPRO_USER_CODE_REGION_END
        }

normally it looks like:


return EntityFieldsFactory.CreateEntityFieldsObject(HOO.LARS.BLL.EntityType.VO_CrewMemberEntity);

I now my code shouldn't disappear but I dont want the code above to be placed in front of mine again

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Jul-2008 04:22:36   

c_pousson wrote:

my expression for the field looks like this:

IEntityField2 fullNameField = new EntityField2("FullName",
                    new Expression(Person.LastName,ExOp.Add,Person.FirstName));

that works but it returns SchmoeJoe I need the expression to return Schmoe, Joe. How do I achieve this.

IEntityField2 fullNameField = new EntityField2("FullName", 
                new Expression(
                        new Expression( PersonFields.LastName, ExOp.Add, ", "),
                        ExOp.Add, 
                        PersonFields.FisrtName));

c_pousson wrote:

also, we are regenerating code a lot. how do I stop the new code from being deleted on a regen

Everything in CODE_REGIONS is kept between generations. No worries wink You also could (and should if possible) use partial classes.

David Elizondo | LLBLGen Support Team
c_pousson
User
Posts: 12
Joined: 03-Jul-2008
# Posted on: 26-Jul-2008 06:15:29   

duh, that code makes complete sense

thanks alot man.

c_pousson
User
Posts: 12
Joined: 03-Jul-2008
# Posted on: 28-Jul-2008 17:46:51   

thanks, got it.