SubSonic Forums
All Your Database Are Belong To Us

RepositoryRecord: Inherit from TableObject

Latest post 08-19-2008 1:41 AM by Juergen. 2 replies.
  • 08-18-2008 12:37 PM

    RepositoryRecord: Inherit from TableObject

    Well, I´m not quite sure, if this is possible at all, but maybe someone has a good solution for me.

    I have a table in my DB that holds a few different "types" of records. All types have a few thinks in common, so I created a partial class "MyTable" that extends the auto generated "MyTable" class. But some methods differ. I want to have a function "Calculate" which is unique for every type. So I thought I could easily inherit from MyTable to achive that.
    Well, that works, when using ActiveRecord, because it loads and saves itself.

    But I use RepositoryRecord. To retrive a row from my db I use the command:
    mytable foo = DB.Get<MyTable>(1)

    But I cannot use this code:
    mytableTypX foo = DB.Get<MyTable>(1)
    or
    mytableTypeX bar = DB.Get<MyTableTypeX>(1)

    Both types dont work.


    Another thing I tried is a class that implements IRecordBase
    In the constructor I load a private MyTable-object and for every method or property to implement I pass the method to the object.
    i.e.:
    return _mytable.GetColumnValue(columnName)

    The advantage of this it that I can control which columns of the underlying table are available in the class.
    But I'm searching for a solution to use the DB.Get / DB.Save methods with the inherited , which doesn´t work, because MyTable cannot be converted to MyTableTypeX.

     

    I hope that was clearly expressed, if not I could provide an example.

     

  • 08-18-2008 3:11 PM In reply to

    Re: RepositoryRecord: Inherit from TableObject

    Example:

    You can convert Apple to Fruit but you can't convert Fruit to Apple

    If I am I because I am I, and You are You because You are You, then I am I, and you are you. But If I am I because You are You, and You are You because I am I, then I am not I and You are not You. -Rabbi of Kotzk

  • 08-19-2008 1:41 AM In reply to

    Re: RepositoryRecord: Inherit from TableObject

    Ok, that makes sence :-)

    good answer. thanks!

Page 1 of 1 (3 items) | RSS