Separate Read/Write Connection for SubSonic

纵饮孤独 提交于 2019-12-02 11:53:17

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/828736/separate-read-write-connection-for-subsonic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!