I have an assembly with an EDMX model. I can successfully create a DbContext
specifying in the constructor a connection string with a reference to that assembly (metadata=res://MyAssembly/MyModel.csdl|res://MyAssembly/MyModel.ssdl|res://MyAssembly/MyModel.msl ...
), and in that case everything works fine.
However, now I'm faced with a situation where I'm getting an existing DbConnection
from an external source, as well as an existing DbTransaction
. I'd like to have a strongly-typed Entity Framework view over this DbConnection
. So, instead of using the connection-string DbContext
constructor, I am using a different DbContext
constructor that takes a DbConnection
(and then using context.Database.UseTransaction()
to set the existing transaction).
In this case, as soon as I try accessing one of my tables, I am getting an error, The entity type MyType is not part of the model for the current context.
- it seems that my model isn't "attached" to the existing DbConnection
.
So, my questions are:
- Is it possible to somehow "attach" a model from my EDMX-containing assembly to an existing
DbConnection
? - I've noticed there's a
DbContext
constructor that takes both aDbConnection
and aDbCompiledModel
. This seems to be exactly what I need. How can I extract aDbCompiledModel
from an existing EDMX-containing assembly?