Adding properties to an existing object retrieved using SubSonic

与世无争的帅哥 提交于 2019-12-11 06:36:57

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/1480286/adding-properties-to-an-existing-object-retrieved-using-subsonic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!