Create EDMX-file while applying Code First

29Mar

Code first is a very nice feature, especially when you use the migration feature, but what if you are applying the MVVM pattern and want to generate view models from your code first model classes? This can be achieved with T4 templates. But a model generating T4 template, such as that one that generates POCO-classes from an edmx file, requires an edmx file. But when you are using code first this file is, by design, missing. So we need a way to generate an edmx file. This can be achieved with a single static method provided by the Entity Framework. The method of interest is EdmxWriter.WriteEdmx. You can use this method as follows: