Search code examples
subsonicobjectpropertiespolymorphism

Adding properties to an existing object retrieved using SubSonic


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.


Solution

  • 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 
        } 
      }
    }