We develop our ADO.NET EF model from the development environment db and then when finally run it to the production we might find that DBA might have added few rules or renamed the database columns. Then our application would start throwing errors. One easy way to get it rectified is to run query against each entity and catch if any error. Otherwise EF gives some public API to use.
I have created my edmx from my dev database and it has just two columns.
Now at production let’s suppose my column is EmpNameTest. How can I programmatically check the difference?
I was going through the tool EdmGen.exe and it gives us an option to validate via
EdmmGen /mode:ValidateArtifacts /inssdl:Model1.ssdl /inmsl:Model1.msl /incsdl:Model1.csdl
All the three files can comes from your edmx file. If you choose the option from edmx file to be part of your output directory, then it will same all of then individually to your output directory.
Now, I will generate the ssdl at runtime by reading the production database, this gets saved to my output directory.
Now call it from your method,
Then run the validate method as below,
I found this solution from the EdmGen2.exe. You will find the whole source code available at http://code.msdn.microsoft.com/EdmGen2
Two points before you try it out,
nice article - stumbled across this in my research for hosting edmx generation outside of VS. thanks!
Hi, I'm trying to use your code, but when I call MetadataItemCollectionFactory.CreateStorageMappingItemCollection I get error(in mErrors) "The version of EdmItemCollection must match the version of StoreItemCollection." Any idea what this could mean? Thank you.