views:

238

answers:

1

I think this is more of a polymorphism question but it applies to SubSonic table objects...

Here's the thing (and I love this one):

TblUser userObj = new TblUser(1);

Which fills userObj's properties with all of PK=1's goodies.

Now, I'd like to add more properties to the existing user object, for example, an ArrayList property of say, account numbers.

I've seen questions like this around - "add a property to an existing object...", but in this case, would it be most-recommended to create a user wrapper object, then have a TblUser property type, and my own other additional properties in this?

Ok, so it looks like once-again I have come up with a solution to this, but am still curious about the possibility of adding properties to existing objects.

Thanks.

+4  A: 

All the generated SubSonic classes are partials so all you need to do to add extra properties/methods to them is to create your own partial class with the same name in the same namespace and the two will be merged at compile time. For example for your TblUser class:

public partial class TblUser
{
  public List<AccountNumber> AccountNumbers
  {
    get 
    {
      // Get and return the AccountNumbers 
    } 
  }
}
Adam
John, thanks for the answer.However, I'm populating the object with TblUser(userID) - nice... but I'm having an issue in my partial class:namespace My.DAL{ public partial class TblUser : PayTrail.DAL.TblUserCard { public TblUser() { } public TblUser(long userID) { moreValues = "more values!!!"; } private string moreValues; public string MoreValues { get { return moreValues; } //set { moreValues = value; } } }}
ElHaix
eew. no code there. Here's the thing I the TblUser() object populates with user-related data, once the userID is passed. The problem is that when I reference TblUser in my code, it only sees the MoreValues property and none of it's parents.
ElHaix
So... I've got an object w/ one constructor called UserDetails(long userID). The UserDetails constructor populates the TblUser object, which is exposed through a TblUser UserObj property in UserDetails.So UserDetails.UserObj.FirstName (kinda ugly), and UserDetails.FullName - which is my own custom property. So how can I optimize this?
ElHaix