SubSonic 的独立读/写连接

发布于 2024-07-19 04:27:52 字数 95 浏览 3 评论 0原文

我们客户生产环境的安全策略要求我们使用单独的连接来执行数据库的写入和读取。 我们决定使用 SubSonic 来生成 DAL。 所以我有兴趣知道这是否可能,如果可能的话如何?

The security policy at our client's production environment requires that we use separate connection to execute writes and read to and from database. We have decided to use SubSonic to generate our DAL. So I am interested in knowing if it is possible and if yes how?

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

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

发布评论

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

评论(1

旧夏天 2024-07-26 04:27:52

您可以指定 SubSonic 在运行时使用的提供程序。 因此,您可以在从数据库加载时指定读取提供程序(使用您的读取连接字符串),然后在要保存到数据库时指定写入提供程序(使用您的写入连接字符串)。

以下未经测试,但我认为它应该为您提供总体思路:

        SqlQuery query = new Select()
            .From<Contact>();

        query.ProviderName = Databases.ReadProvider;

        ContactCollection contacts = query.ExecuteAsCollection<ContactCollection>();
        contacts[0].FirstName = "John";
        contacts.ProviderName = Databases.WriteProvider;
        contacts.SaveAll();

You can specify the provider SubSonic is using at runtime. So you would specify the read provider (using your read connectionstring) when loading from the database and then specify the write provider (using your write connectionstring) when you want to save to it.

The following isn't tested but I think it should give you the general idea:

        SqlQuery query = new Select()
            .From<Contact>();

        query.ProviderName = Databases.ReadProvider;

        ContactCollection contacts = query.ExecuteAsCollection<ContactCollection>();
        contacts[0].FirstName = "John";
        contacts.ProviderName = Databases.WriteProvider;
        contacts.SaveAll();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文