EF: Model in subfolder and Metadata with "Embed In Output Assembly"
Posted: Mon 15 Dec 2014 15:26
We want to have multiple models in a project. Each model should reside in it's on subfolder. We use the Studio Plugin.
If we select Metadata Artifact Processing = "Embed In Output Assembly" then we find the following files in the \obj\Debug folder:
Folder1.Model1.csdl
Folder1.Model1.msl
Folder1.Model1.ssdl
So the correct connection string would be something like this:
which is generated correctly in the app.config, too.
With the dbcontext Template and "Save connection string in App.Config" = false the connection string in the context file constructor now is
which seems to be wrong (and produces a runtime error because of the missing "Folder1" part). Can you confirm this behavior?
The second question would be: How do we get the "Folder1" part (seems to be the complete folder path to the model in the project) in the dbcontext template? We have to customize the context file generation, because we want to have one single connection string in the App.Config. So we must add the metadata to this string for each context. Our code already works if all models are in the project root.
For better performance the res://*/ should be replaced with the res://MyDefaultNamespace/, is that right?
If we select Metadata Artifact Processing = "Embed In Output Assembly" then we find the following files in the \obj\Debug folder:
Folder1.Model1.csdl
Folder1.Model1.msl
Folder1.Model1.ssdl
So the correct connection string would be something like this:
Code: Select all
(..)metadata=res://*/Folder1.Model1.csdl|res://*/Folder1.Model1.ssdl|res://*/Folder1.Model1.msl;(..)With the dbcontext Template and "Save connection string in App.Config" = false the connection string in the context file constructor now is
Code: Select all
(..)metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;(..)The second question would be: How do we get the "Folder1" part (seems to be the complete folder path to the model in the project) in the dbcontext template? We have to customize the context file generation, because we want to have one single connection string in the App.Config. So we must add the metadata to this string for each context. Our code already works if all models are in the project root.
For better performance the res://*/ should be replaced with the res://MyDefaultNamespace/, is that right?