Referencing EF Resources in a Specific Assembly

This post and sample application demonstrate a possible issue with the way that Entity Framework loads the embedded metadata resources (csdl, msl, ssdl) for the entity model. In my application, all assemblies in some specific directory are discovered and loaded at runtime. Think of it as a sort of plugin model. The application allows for multiple versions of the same assembly to be loaded, and each dll follows the [AssemblyName].[Version].dll naming scheme....

July 13, 2013

Pass a Connection String to a Generated DbContext

The default DbContext generated with your Entity Data Model has one constructor that takes no arguments. If you need to build the connection string programatically and pass it to the DbContext, you will have to add your own constructor. However, if you do this in the generated file, {ModelName}.Context.cs, you will lose your changes the next time the {ModelName}.Context.tt script is run. The solution is to edit the script, {ModelName}.Context.tt. Just add the following code after the code to generate the default constructor (around line 71)....

February 3, 2013