Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to setup EF Trace on an Entities ObjectContext without passing in the connection name
    primarykey
    data
    text
    <p>I'm writing a reusable base repository class where the developer will pass in a generic representing the <code>ObjectContext</code> and the base repository will create an instance of it with <code>Activator.CreateInstance</code>. When debugging I want to make use of the nuget package <code>CommunityEFProviderWrappers.EFTracingProvider</code>. So my code to setup the object context looks like this:</p> <pre><code> public void RenewDataContext() { #if DEBUG // get the default container name var containerName = Activator.CreateInstance&lt;T&gt;().DefaultContainerName; // create an instance of the object context using EF Trace Context = (T)Activator.CreateInstance(typeof(T), EFTracingProviderUtils.CreateTracedEntityConnection(containerName)); Context.EnableTracing(); #else Context = Activator.CreateInstance&lt;T&gt;(); #endif } </code></pre> <p>The problem is that this always throws the following error when it tries to create an instance of the <code>ObjectContext</code> with the <code>EFTracingProvider</code>: <em>"Schema specified is not valid. Errors: \r\n(0,0) : error 0175: The specified store provider cannot be found in the configuration, or is not valid."</em></p> <p>If I replace <em>containerName</em> with the name of the connection string in the web config and don't do the first <code>Activator.CreateInstance&lt;T&gt;()</code> then it works fine. So the issue has something to do with the fact that I create the first instance and then the second.</p> <p>Here is what I have tried:</p> <ol> <li>dispose and null out the first instance. </li> <li>close the connection on the first instance. </li> <li>put the first instance in a <em>using</em> statement.</li> <li>explicitly define the assembly containing the ObjectContext in the connection string in the web.config in the startup project (<a href="https://stackoverflow.com/questions/1074337/metadataexception-when-using-entity-framework-entity-connection">MetadataException when using Entity Framework Entity Connection</a>)</li> </ol> <p>I am trying to avoid having the developer pass in the generic type of the <code>ObjectContext</code> AND the name of the connection string. That seems kind of redundant.</p> <p>So my question is: <strong>How do I get the connection name from the generic representing the object context and still be able to use it to create an instance of the object context using the EntityConnection generated by EF Trace?</strong></p> <p><em>My question is about why this method doesn't work, not about possible work arounds.</em></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload