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:

  1. Go to Announcing the Entity Framework POCO Template update for Visual Studio 2010 Beta 2 and download the attached zip file (or click here)
  2. Unpack it anywhere
  3. Run the C# andor VB installer
  4. Open Visual studio 2010 RC
  5. 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 * 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


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

Technorati Ознаке: ,

Posted on February 17, 2010, in Uncategorized. Bookmark the permalink. 8 Comments.

  1. 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.

  2. 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

  3. Danny,
    make sure that the line containing inputFile = … contains a valid path to your edmx file (most probably your issue)

  4. I think I'll stick to NHibernate…

  5. 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.

  6. Kron d.o.o., tvrtka specijalizirana za izradu poslovnih knjigovodstvenih programa, programa za poslovanje autobusnih kolodvora i drugih po narudžbi. Kron d.o.o.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: