开发者

Subsonic SQLite Multiple Files

开发者 https://www.devze.com 2022-12-30 15:56 出处:网络
I have an application that must be accessed for many users. To optimize the performance I intend to store each user profile information at a independant database file.

I have an application that must be accessed for many users. To optimize the performance I intend to store each user profile information at a independant database file.

I need everytime a user login the application, to setup a new provider linked with his own database. All databases have the same structure. So while querying user the commom generated DAL classes must switch for the database file relative the the user.

I开发者_JAVA技巧s there a way for configure SubSonic for doing that switch at runtime?

Thanks.


Well, assuming we 're talking about SubSonic3:

I have made a patch for this and logged it as an issue in the SubSonic Templates project on github, where the source is available. You can find the issue (and a link to the code) here.

After you apply the patch, you will have a new DefaultDataProvider property which does exactly what you want. Use it like this (e.g. after a user logs in):

YourSubSonicGeneratedNamespace.YourDatabaseName.DefaultDataProvider =
    SubSonic.DataProviders.ProviderFactory.GetProvider(
        "your connection string here",
        SubSonic.DataProviders.DbClientTypeName.SqlLite);

And you 're good to go.

For SubSonic 2, this answer sounds like what you want.


With subsonic 2 I use an approach where I inject the provider at runtime rather than loading it from the app.config file.

Look at my answer here: Subsonic in a VS2008 Add-In woes

Instead of just using one provider you could create one for every user who starts the application and change the default provider as needed.

0

精彩评论

暂无评论...
验证码 换一张
取 消