Inheritance

Posts   
 
    
Homer00
User
Posts: 10
Joined: 27-Dec-2010
# Posted on: 15-Mar-2011 20:42:33   

Hi,

I'm trying to inherit an EntityClass. I want to override ToString().

E.g:

llblgen.Student llblgen.Class etc

I want to add some "student objects" into a combo (for example) and i need to override .ToString() to implement name and surname of the student into the combo.

I'm trying to do this:

public class MyStudent: llblgen.Student
{
        public override string ToString()
        {
            return base.Name + " " + base.Surname;
        }
}

but after i do something like this:

llblgen.Student stu = new Student(1);
mystudent mstdnt = (mystudent)stu;

and then, exception.

I need some help with this or a way to do it better.

Thank you.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 15-Mar-2011 22:31:34   

You don't need to either inherit from Entity, or override ToString() - a better way would be to extend the existing entity with a property of your own naming

public string FullName
{
get{return this.FirstName + ' ' + this.LastName;}
}

This can be added to one of the user code regions in the generated entity (it will not get overwritten when you regenerate) or in a partial class (all of the entity classes are generated as partial classes to allow this sort of extension)

Then when you bind to the comboBox, just set the .DisplayMember property to your FullName property.

matt

Homer00
User
Posts: 10
Joined: 27-Dec-2010
# Posted on: 16-Mar-2011 11:05:17   

MTrinder wrote:

You don't need to either inherit from Entity, or override ToString() - a better way would be to extend the existing entity with a property of your own naming

public string FullName
{
get{return this.FirstName + ' ' + this.LastName;}
}

This can be added to one of the user code regions in the generated entity (it will not get overwritten when you regenerate) or in a partial class (all of the entity classes are generated as partial classes to allow this sort of extension)

Then when you bind to the comboBox, just set the .DisplayMember property to your FullName property.

matt

I've found it! ok. so much thanks.