Question

I was able to get active record running right away. The instructions for getting started were great and in no time I had built a webservice that would let me create and read widgets in my existing db. It was awesome. When it came to updating though, things fell apart. I would edit the object on the client and send it back to the service but when the service saved it, it would just create a new one. I reasoned that this meant that I would need to re-query the db and assign the values sent up to the service from the client but my boss said that would be hacky and that the repository pattern would be better because could use pocos. Unfortunately that's the extent of the guidance I've gotten. So here are my questions.

  1. Are the t4 templates only good for active record or will they build up your simple repository for you too. Eg, is there something that will gen up my pocos too or are they all 'roll your own'?

  2. Has anyone seen a working example of a subsonic 3 tier solution? I've read about them but are there any samples floating around?

The active record samples/ screencasts were really easy to follow because they started at the same point I was starting with. The simple repository ones seemed to focus more on migrations and other advanced features and being that this stuff is new to me, I don't know enough to connect the dots.

Ugh. There's nothing quite like having a deadline to learn something and have it running by the end of the week. Any advice would be welcome, even if it's rtfm with a link to the manual I should have read.

Thanks in advance

Was it helpful?

Solution

If you want to use a repository pattern you can either use the linq templates or use the simple repository which does not require any t4 templates.

With simple repository you create the pocos yourself. Subsonic can create or update the database scheme for you if you choose:

var repository=new SimpleRepository(SimpleRepositoryOptions.RunMigrations);

but If you ask me I would choose SimpleRepositoryOptions.None and update the database by myself.

Anyway, your initial problem with the ActiveRecord templates could be fixed pretty easy. I suggest your ActiveRecord object is serialized on the client side and deserialized on the server.

The default constructor of an ActiveRecord object calls the Init function which looks like this:

    void Init(){
        TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
        _dirtyColumns=new List<IColumn>();
        if(TestMode){
            <#=tbl.ClassName#>.SetTestRepo();
            _repo=_testRepo;
        }else{
            _repo = new SubSonicRepository<<#=tbl.ClassName#>>(_db);
        }
        tbl=_repo.GetTable();
        SetIsNew(true);
        OnCreated();       

    }

As you can see, the internal repository is created and SetIsNew(true) is executed. The only thing you have to do is to call myitem.SetIsNew(false) after the object gets populated with the deserialized values. I suppose that is sufficient to tell subsonic to do an update query during save.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top