Daily Archives: February 9, 2010

Using the Beta 2 EF POCO Template with VS2010 RC

Update: After realizing that we still want access to it, the team has made the Beta 2 file available again. You can get it from their original blog post, not from the Visual Studio Gallery links but look for a zip file at the bottom of the post.

But there’s more! While I had managed to figure out one big difference (TemplateFileManager name changed) between the old include file and the new include file it wasn’t enough. which is why after a few hours I gave up and went back to the old include file. But Nikola Malovic figured out the second piece which was how to replace the WriteFiles method which is no longer there! Check out his blog post for the super secret trick!

————————————————–

Entity Framework’s T4 templates all have a dependency on a file that includes additional specialized methods.

If you look at the top of the templates (ENtityObject, POCO or Self-Tracking Entiteis) there is a pointer to a ttinclude file.

<#@ include file="EF.Utility.CS.ttinclude"#>

That file, however, changed after Beta 2. The new templates (EntityObject and STE’s both included in VS2010) work wtih the new version of this file. But the POCO template that was released in December doesn’t.

However, I have a trick to have your cake and eat it too until the new POCO template comes along.

This is just a temporary workaround until a new set of templates hits the airwaves. 🙂

The ttinclude files live here:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes

The new one has a file date of Jan 6, 1010.

You can grab the ttinclude file from Beta 2 and rename it. I’ve renamed mind:

EF.B2.Utility.CS.ttinclude

The file date on that one is Sept 15, 2009.

Then copy it into the Includes folder with the new includes.

Now when you create a new POCO template, you’ll first get error message about TemplateFileManager not existing. In the new include, that’s been renamed to EntityFrameworkTemplateFIleManager. But that’s not hte only change. Fixing that name in your template will not help.

Instead,  just change the reference in the template file to read the Beta 2 include :

<#@ include file="EF.B2.Utility.CS.ttinclude"#>

Then the POCO template will use the Beta 2 version of the include and you can go on your merry way.

Thanks to Dane Morgridge for sending me the VSIX file from the Beta 2 POCO since I had installed directly rather than downloading it to my computer.

Video and Q&As from my Top 10 Treats in EF4 WebCast

The video from my webcast, Top 10 Treats in Entity Framework 4 is available on Oreilly’s website: http://www.oreillynet.com/pub/e/1517.

I just discovered that WebEx saved the chat window from my O’Reilly webcast last month. So I thought I would pick out the quesitons and answer them here although I did answer some of them at the end of the webcast:

Q address NOT Address??

Someone noticed that an entity was named address. The pluralization support in the VS2010 EDM Designer does not fix up bad capitalization from the database which this was meant to highlight. Another viewer replied: it’s address and not Address because the original table was with a lower case ‘a’. VS2010 supports pluralization, but doesn’t change capitalization

Q These classes are not POCO, correct? What do I have to do to have POCO and generate db schema?

In the early part of the demo I was wroking with the default EntityObjects. To use POCO classes to generate db schema you’ll want to skip the model and use the Code-Only support that is part of the EF Feature CTP: Updated Feature CTP Walkthrough- Code Only for Entity Framework

This is awesome. We will all forgot how to sql.
Not a question, but a funny comment I wanted to share.

Q What about update database from model?

Update database from model has been supported sine the first version of EF. It will bring in new tables and new properties in tables but it will not modify property types. Be aware that any changes made manually to the SSDL get overwritten during this process.

Q. How much control does the developer have over the generated SQL DDL?
I answered this one at the end of the webcast. There is a T4 template that drives the DDL generation so that’s customizable.

This thing needs a pause button! LOL
Another funny comment I thought I would share. Yeah it is tough doing these webcasts that have a time limit! 🙂

Q. can you control lazy loading on a per entity level?
I happened to answer this question as I was talking about lazy loading and the person who asked then said: “ah thanks … ok, so per context only.”

Q. How easy is it to mock entities for nUnit or xUnit testing?

The new IObjectSet interface makes it totally possible to mock entities now. Many people have written blog posts about this. Here’s mine: http://thedatafarm.wpengine.com/blog/data-access/agile-entity-framework-4-repository-part-5-iobjectset/

Q: I heard something about "model functions" or "schema functions", implying I can do calculations for fields OR create views over entities in the EDM / .edmx file. Is this true?
Yes. Check out http://thedatafarm.wpengine.com/blog/data-access/ef4-model-defined-functions-level-1-amp-2/

Q: how does Oracle support compare? Is it as functionally complete? Is it as stable/bug free?

Oracle providers are available from DevArt and Data Direct. As far as I know they are both very solid. Functionally complete? Dunno.

LINK to EF POCO Adapter for EF1: code.msdn.microsoft.com/EFPocoAdapter