views:

385

answers:

1

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?

+4  A: 

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();
Adam
@Adam I would love to have a piece of code to illustrate it!
TheVillageIdiot
Edited my answer to give an example, its c# but should easily translate if necessary
Adam
@Adam so many thanks, no need for translation I'm coding in C#.
TheVillageIdiot