简体   繁体   English

3层应用程序的Subsonic存储库入门

[英]Getting Started With Subsonic Repository for a 3 tier app

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. 入门说明非常棒,并且我很快就构建了一个Web服务,该服务可以让我在现有数据库中创建和读取小部件。 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. 我认为这意味着我将需要重新查询数据库并分配从客户端发送到服务的值,但是我的老板说这会很hacky,并且存储库模式会更好,因为可以使用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. T4模板仅适合用于活动记录吗?还是它们也会为您建立简单的存储库。 Eg, is there something that will gen up my pocos too or are they all 'roll your own'? 例如,是否有一些东西也会使我的pocos产生出来,或者它们都是“自己滚”的?

  2. Has anyone seen a working example of a subsonic 3 tier solution? 有没有人看过亚音速3层解决方案的有效示例? 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. 任何建议都将受到欢迎,即使它是rtfm,并附有我应该阅读的手册链接。

Thanks in advance 提前致谢

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. 如果要使用存储库模式,则可以使用linq模板,也可以使用不需要任何t4模板的简单存储库。

With simple repository you create the pocos yourself. 使用简单的存储库,您可以自己创建pocos。 Subsonic can create or update the database scheme for you if you choose: 如果选择以下选项,则Subsonic可以为您创建或更新数据库方案:

var repository=new SimpleRepository(SimpleRepositoryOptions.RunMigrations);

but If you ask me I would choose SimpleRepositoryOptions.None and update the database by myself. 但是如果您问我,我会选择SimpleRepositoryOptions.None并自己更新数据库。

Anyway, your initial problem with the ActiveRecord templates could be fixed pretty easy. 无论如何,您可以轻松解决ActiveRecord模板的最初问题。 I suggest your ActiveRecord object is serialized on the client side and deserialized on the server. 我建议您将ActiveRecord对象在客户端进行序列化,然后在服务器上进行反序列化。

The default constructor of an ActiveRecord object calls the Init function which looks like this: ActiveRecord对象的默认构造函数调用Init函数,如下所示:

    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. 如您所见,将创建内部存储库并执行SetIsNew(true) The only thing you have to do is to call myitem.SetIsNew(false) after the object gets populated with the deserialized values. 您唯一要做的就是在用反序列化的值填充对象之后调用myitem.SetIsNew(false) I suppose that is sufficient to tell subsonic to do an update query during save. 我想这足以告诉亚音速在保存期间进行更新查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM