开发者

DataContextProvider

开发者 https://www.devze.com 2022-12-09 18:37 出处:网络
Going from the example given here... http://ericswann.org/blog/archive/2009/04/06/linq-to-sql-datacontext-provider-revisited.aspx

Going from the example given here...

http://ericswann.org/blog/archive/2009/04/06/linq-to-sql-datacontext-provider-revisited.aspx

I'm trying to use the datacontext between the MembershipProvider and the RoleProvider.

For instance, when I call Membership.GetUser(XXXXXX) in the RoleProvider, I get an error because it pulls an item from one datacontext and tries to use it (hence th开发者_Go百科e need for the repository)

But I am ...really stupid, and this is some pretty advanced stuff. Seeing as how I do not get to 'instantiate' the Providers, does anyone have an idea how I might go about using this?


First of all pick your datacontext caching strategy. Use DataContextThreadCache if you're working in winforms, where the context is cached in your running thread context. Use DataContextWebCache if you're working with web apps where the context is cached in HTTP run-time cache.

To register your datacontext look at DataContextProvider.RegisterDataContext and its overloads. Here is an example:

DataContextProvider.RegisterDataContext<YourDataContextType, YourCacheStrategyType>(contextKey, contextConnectionString)

contextKey: is the key you will use to retrieve your data context with.

contextConnectionString: is the connection string for your data context.

This call will use the type of DataContext you specified to create an new instance of it. It will then cache it using the specific caching strategy you specified also. This should probably be called somewhere during the initialization phase of your application. Your repository can then use GetDataContext as outlined in that blog post to get the context instance.

0

精彩评论

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