开始使用 3 层应用程序的 Subsonic 存储库

发布于 2024-10-14 12:19:35 字数 566 浏览 5 评论 0原文

我能够立即运行活动记录。入门说明非常好,我很快就构建了一个 Web 服务,可以让我在现有数据库中创建和读取小部件。太棒了。但到了更新的时候,事情就崩溃了。我会在客户端上编辑对象并将其发送回服务,但是当服务保存它时,它只会创建一个新对象。我推断这意味着我需要重新查询数据库并分配从客户端发送到服务的值,但我的老板说这会很hacky并且存储库模式会更好,因为可以使用pocos。不幸的是,这就是我得到的指导的范围。这是我的问题。

  1. t4 模板仅适用于活动记录还是会构建 为您建立简单的存储库 也。例如,有没有什么东西 也会生成我的 pocos 还是它们 所有“自己动手”?

  2. 有人见过亚音速 3 层的工作示例吗 解决方案?我读过有关他们的内容但是 有没有样品漂浮 周围?

活动记录样本/截屏视频非常容易理解,因为它们与我开始的时间点相同。简单的存储库似乎更关注迁移和其他高级功能,并且这些东西对我来说是新的,我不知道足够的知识来连接这些点。

啊。没有什么比设定一个学习的最后期限并在周末之前将其运行更好的了。任何建议都会受到欢迎,即使它是带有我应该阅读的手册链接的 rtfm。

提前致谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无人问我粥可暖 2024-10-21 12:19:35

如果您想使用存储库模式,您可以使用 linq 模板 或使用不需要任何 t4 模板的简单存储库。

使用简单的存储库,您可以自己创建 pocos。如果您选择,Subsonic 可以为您创建或更新数据库方案:

var repository=new SimpleRepository(SimpleRepositoryOptions.RunMigrations);

但如果您问我,我会选择 SimpleRepositoryOptions.None 并自己更新数据库。

不管怎样,您最初的 ActiveRecord 模板问题可以很容易地解决。
我建议您的 ActiveRecord 对象在客户端序列化并在服务器上反序列化。

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();       

    }

如您所见,创建了内部存储库并执行了 SetIsNew(true)
您唯一需要做的就是在对象填充反序列化值后调用 myitem.SetIsNew(false) 。我认为这足以告诉 subsonic 在保存期间执行更新查询。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文