At the moment i have an application (web/silverlight) where the connectionstring for my ObjectContext is dynamic. It is based on how a user logs in because each of my customers have their own database. ie.. username@domain. I’m trying to find a way to use the EFContextProvider which would be by either passing the ObjectContext through the constructor, or by overriding the GetConnectionString, which sadly both aren’t supported.
Is there a way to accomplish this, or can i download the source for the EFContextProvider somewhere so i can implement it myself ?
Thanks in advance.
This question was posted by Marcel on our IdeaBlade forums. I am reposting the question and answer here since I think it will be useful to the Breeze Stack Overflow community.
You shouldn’t have to download the source and modify it for such a simple thing. And now you won’t have to.
We’ve pushed to GitHub a simple update to
EFContextProvider. This change will appear in the next Breeze Runtime version (> 0.81.2).Where
EFContextProviderused to create the ‘T’ (your ObjectContext/DbContext) as follows:It now calls upon a virtual method,
T CreateContext()instead, whose default implementation is:protected virtual T CreateContext() { return new T(); }Override and replace that in your
EFContextProvidersubclass and you will be able to make your context of type ‘T’ just the way you like it.N.B.: The base
EFContextProviderwill still do a little post-creation configuration to make sure it behaves as we expect; we don’t want the context doing any lazy loading or creating proxies.So if ‘T’ is an
ObjectContext, the provider will do this:and if ‘T’ is a
DbContextit will do this: