Announcing the Entity Framework POCO Template update for Visual Studio 2010 Beta 2


The information in this post is out of date.

Visit msdn.com/data/ef for the latest information on current and past releases of EF.


Note: The download links in Visual Studio Gallery have been disabled while we prepare to release a refresh of the template that is compatible with Visual Studio 2010 Release Candidate. In the meanwhile, you can use the VSIX installers attached to this post, which are compatible with Visual Studio 2010 Beta 2 only.

Today we are releasing an updated version of the POCO entity generation templates that work with Visual Studio 2010 Beta 2. You can download them immediately using the Extension Manager inside Visual Studio 2010 Beta 2 or from the Visual Studio Gallery page, here for the C# version and here for the Visual Basic version.

Usage of the templates is described in the updated POCO Template Walkthrough.

The original version of this T4 template was included in the Entity Framework Feature CTP 1, and since we released the Feature CTP 2 last November without this feature, we have heard from lots of customers that they wanted us to work on a new version of it. 

Besides being compatible with Beta 2, the new template includes a number of bug fixes, generated code improvements, handling of relationship fixup that includes support for Foreign Keys in the Model (see more details here about this new feature of Entity Framework) and compatibility with change tracking POCO Proxies and ObservableCollection<T>.

The POCO Template is not going to be part of Visual Studio 2010 in RTM. Instead the current plan is to continue delivering updates for it through the Extension Manager and the Visual Studio Gallery.

Known issues in this version

  1. The POCO Template does not work with ASP.NET WebSite projects: A bug in multiple output file support prevents the POCO Template from working on WebSite projects. A fix will be available in a future update. In the meanwhile, you can place the template in a separate class library project and add a reference to the class library from the WebSite.
  2. Running a query with Include and MergeOption equal to NoTracking may cause an exception: There is a problem in the interaction between the implementation of relationships fixup code in classes generated by the POCO template and the change tracking POCO Proxies enabled by the POCO Template.  We are currently investigating this issue.
  3. Detach can cause nullable foreign keys properties to be nulled: The implementation of relationship fixup cannot distinguish the reason an entity is being removed from an object graph. When Detach is applied to an entity that is related to others through foreign key associations, fixup logic will react to references being nulled and elements being removed form collections and will set the corresponding FK properties to null. We are currently investigating this issue.
  4. The AssociationChanged event can be raised twice: The AssociationChanged event is raised twice with CollectionChangeAction.Add when fixup occurs in the model such that a collection is modified. We are currently investigating this issue.

 

Feedback is welcome

If you find any problem or you are missing any feature you would like to see us include in future versions, you can enter bugs and suggestions through the Microsoft Connect page for the Visual Studio 2010 & .NET Framework 4.0 Beta located here.

You can also provide feedback or asks your questions in the Entity Framework Pre-Release Forum.

Diego Vega,
Entity Framework Team

EF4Beta2PocoTemplates.zip

Comments

  • Anonymous
    January 26, 2010
    Is that true that the Entity Framework will not work against database tables that have no primary and/or foreign keys set?

  • Anonymous
    January 26, 2010
    Diego, Nice one.  Been waiting for this.   Thanks very much all your hard work is appreciated! Alec

  • Anonymous
    January 27, 2010
    How does the POCO template get lazy loading to work. I see in the getter that ICollection is initiazed to FixupCollection.  Does that mean

  1.       When we query using EF, collection is getting initialized to EntityCollection that does the fixup.
  2.       When we instantiate an entity with new, the collection is initialized as FixupCollection that does the fixup
  3.       When we use CreateObject the collection is initialized to EntityCollection that does the fixup? I think it would be confusing because when I am creating the entity and something gets added to the collection, the UI would be notified because FixupCollection derives from ObservableCollection which implements INotifyingChanging. However when the object is retrieved from query, changes made would not be notified to the UI? Am I correct?
  • Anonymous
    January 28, 2010
    Hi Zeeshan, this is good feedback. We are indeed generating entities that can produce change tracking proxies in this version of the POCO Template, but we are still generating smart collections that do fixup for non-proxy instances. It is also relatively easy to touch the template to inject "this.ContextOptions.ProxyCreationEnabled = false" in the constructor of the generated ObjectContext class and then you will get FixupCollections on all your instances. We have tested a number of mixed proxy and non-proxy scenarios. Unfortunately there are some rough edges still, as described in the “known issues section”. For the particular issue that you raise, you will see different behaviors in collections between proxies and non-proxies, and even between WinForms and WPF databinding. Keep in mind that while EntityCollection does not implement INotifyCollectionChanged, it does implement IListSource, and the IListSource.GetList method returns an IBindingList that uses WinForms style change notification. Hope this answers your question, Diego.

  • Anonymous
    January 29, 2010
    I setup a small console application; the new T4 generated based on 2 database tables (Resource and Role) using a function call i get resource id # 1. Resource res = Get(1); SaveResource(res); // do not save anything to database In SaveResource I have created a new role and save it. but save does not happen to database. eg: function SaveResource(Resource res) using (var ct = new Entities()) {   res.Roles.Add( GetRole(1) );   ct.Resources.ApplyChanges(r);   ct.SaveChanges(); } am i missing ??

  • Anonymous
    February 03, 2010
    Been waiting for this. Thanks. I would love to see a complete example of using POCO objects with proxies (lazy loading and change tracking) with Wcf Data Services. Currently I am having issues with serialization of some of the auto generated proxies. Regards, Egil.

  • Anonymous
    February 08, 2010
    I tried to download the 'Entity Framework POCO Template for Visual Studio Beta 2 for C#' but when the page loads I get the message 'This item is not yet published.' Thanks, Phil

  • Anonymous
    February 09, 2010
    Hi. I was wondering if it would be possible to put the "Entity Framework POCO Template for Visual Studio Beta 2 for C#" back online while the RC is not out. I was working with and need install it again on another machine. Unfortunately, I did not save the installer... If any one can get me the previous version i would appreciate it.

  • Anonymous
    February 09, 2010
    Hi, I also need the file, can you put it online again? Thanks...

  • Anonymous
    February 10, 2010
    Hi, anyone knows when the template for RC will be released?

  • Anonymous
    March 20, 2010
    What do I do with this ZIP to use the templates?