SubSonic的单独读/写连接 [英] Separate Read/Write Connection for SubSonic

查看:103
本文介绍了SubSonic的单独读/写连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

客户生产环境中的安全策略要求我们使用单独的连接来执行数据库读写操作。我们已决定使用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?

推荐答案

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

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

这篇关于SubSonic的单独读/写连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆