Using the POCO template, get the Entity Framework connection string.

.net app-config c# entity-framework

Question

I need to get my connection string so that I can create a context, and I utilize Entity Framework.

I'm use the POCO model. My context object possesses:

string ConnectionString = "name=MyAppConfigConnectionStringPropertyHere"

Therefore, when I attempt to just create my context, it says

"The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid"

I discovered that there is a GetConnectionString() function in this answer. However, searching online did not turn up the reference I needed to add to get that approach (it is not in my project by default).

As a result, I can't imagine that I'm the only one who wishes to use POCO templates to get a connection string for entity framework. How have others carried this out? I suppose I can simply parse the whole app.config file after reading everything in. But it doesn't seem like it should be that difficult.

I would appreciate any pointers!

1
10
5/23/2017 11:47:05 AM

Popular Answer

The following code provides the most recent ConnectionString for Entity Framework 6.0.

context.Database.Connection.ConnectionString
28
5/8/2017 10:31:57 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow