Spurred on both by the success of Damien Guard in using T4 to generate Linq to SQL code and of Jeff Reed from the EF team who built a prototype for using T4 to generate EF code, I recently hacked something up that makes it fairly easy to use T4 to generate EF classes. This is an early draft--there are a number of "to do" items--but hopefully someone will find it useful.
In order to try it out, all you need to do is:
The output now is mostly the same as what the shipping codegen creates except that:
Already, though, it's nicer to look at, and if you would like to customize the output, this is a much more pleasant starting point than codegen events with the existing code-dom based generator.
Let me know what you think.
very interesting technique, I may consider using it for one of my projects to override some designer code generation issues.
One possible problem function imports. I've found them in your ToDo list, but when I tried to implement them - I found that System.Data.Metadata.Edm.EntityContainer does not expose FunctionImports (it has them but as internal property).
Sorry for not responding sooner. The basic answer for this will be to parse the CSDL XML file directly and get the information from there. It's nice when we can use the metadata APIs to get the info easily, but there are ways around things when they are misisng.
Very interesting approach, and for sure easier than hooking into the original code generation process.
I was trying to make this .tt file dependent upon the .edmx file, as to automatically regenerate when saving the .edmx file. No success however.
Can this be done you think?
There's not a real simple way to accomplish this. The standard T4 mechanism is to just manually generate. We're looking into some ideas to make this more automatic (but still giving control over whether or not you want it to happen all the time) in VS2010, but I don't yet have a good suggestion for you to use with VS2008sp1. If I come up with something, I'll post it to my blog.
T4 templates have been a pretty popular topic lately.  If you have no idea what they are, don’t
Part of the Entity Framework FAQ . 2. Architecture and Patterns 2.1. Does Entity Framework have support
1. Introduction This is the first article of my series about deep dive into ADO.NET Data Services. In
In my MSDN Magazine article on SOA Data Access I recommend exposing Data Transfer Objects (DTOs) from