Using the entity framework POCO template with VS2010 RC (easier way)
A while ago Julie blog posted tutorial on how to use VS 2010 beta POCO T4 templates in VS2010 RC. While I found that post very helpful I had hard time following it and after a bit of playing I think I found easier way how to get POCO template working:
Here are n simple steps:
- Go to Announcing the Entity Framework POCO Template update for Visual Studio 2010 Beta 2 and download the attached zip file (or click here)
- Unpack it anywhere
- Run the C# andor VB installer
- Open Visual studio 2010 RC
- Add a POCO template (New ItemCodeADO.NET POCO Entity Generator
Open the Model TT file being generated by T4 (No need to do anything in *.Context.tt file)
Update L15 of the generated file to be
EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this);
Original content:TemplateFileManager fileManager = TemplateFileManager.Create(this);
Update L678 of the generated file to be
fileManager.Process();
It is originally fileManager.WriteFiles();
And voila – your T4 template is operational without the need to copy anything, no need for VS2010 b2 image files.
Please let me know (here on blog or on twitter @malovicn) if you would have any problems with this steps
February 17th, 2010 - 13:22
Ahh – looks like the team replaced the file online as they said they would.
And hooray. I found the EntityFrameworkTemplateFileManager difference right away but spent a lot of time trying to figure out how to deal with the WriteFiles and finally gave up. I even asked the team but got no reply. THat's why I went back to the original template. Glad you figured it out. I'll update my blog post with a pointer.
julie
February 18th, 2010 - 17:18
This doesn't work; I get the following error:
Error 1 Running transformation: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.IO.FileNotFoundException: Unable to locate file
at Microsoft.VisualStudio.TextTemplating.VSHost.TextTemplatingService.ResolvePath(String path)
at Microsoft.VisualStudio.TextTemplating.VSHost.TextTemplatingService.ResolvePath(String path)
— End of inner exception stack trace —
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.VisualStudio.TextTemplatingEB5A9BAE66DC8DACF545B9EC88E1789A.GeneratedTextTransformation.DynamicHost.ResolvePath(String path)
at Microsoft.VisualStudio.TextTemplatingEB5A9BAE66DC8DACF545B9EC88E1789A.GeneratedTextTransformation.MetadataLoader.TryCreateEdmItemCollection(String sourcePath, String[] referenceSchemas, EdmItemCollection& edmItemCollection)
at Microsoft.VisualStudio.TextTemplatingEB5A9BAE66DC8DACF545B9EC88E1789A.GeneratedTextTransformation.MetadataLoader.CreateEdmItemCollection(String sourcePath, String[] referenceSchemas)
at Microsoft.VisualStudio.TextTemplatingEB5A9BAE66DC8DACF545B9EC88E1789A.GeneratedTextTransformation.TransformText()
at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession session, String source, ITextTemplatingEngineHost host, String& result) 1 1
February 19th, 2010 - 10:43
Danny,
make sure that the line containing inputFile = … contains a valid path to your edmx file (most probably your issue)
April 19th, 2010 - 22:37
I think I'll stick to NHibernate…
May 5th, 2010 - 16:11
As a followup to the post of "malovicn":
The easiest way to prevent the FileNotFoundException is to add the t4 template by right clicking on the background of the entity designer and choose "Add Code Generation Item". If you add the t4 template by using "Add new Item" on your project, you will get the FileNotFoundException.