<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Diego Vega</title><link>http://blogs.msdn.com/diego/default.aspx</link><description>Entity Framework news and sporadic epiphanies</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Entity Framework Feature CTP 2</title><link>http://blogs.msdn.com/diego/archive/2009/11/05/entity-framework-feature-ctp-2.aspx</link><pubDate>Thu, 05 Nov 2009 00:21:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9917658</guid><dc:creator>divega</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/diego/comments/9917658.aspx</comments><wfw:commentRss>http://blogs.msdn.com/diego/commentrss.aspx?PostID=9917658</wfw:commentRss><wfw:comment>http://blogs.msdn.com/diego/rsscomments.aspx?PostID=9917658</wfw:comment><description>&lt;p&gt;We have just released a new version of the Feature CTP that works on top of Visual Studio 2010 Beta 2. I have been focusing on Self-Tracking Entities a lot lately, and so it feels great to have this out for people to try it and give us feedback on it.&lt;/p&gt;  &lt;p&gt;The new version of Code-Only is great too.&lt;/p&gt;  &lt;p&gt;You can see the announcement &lt;a href="http://blogs.msdn.com/adonet/archive/2009/11/04/ado-net-entity-framework-community-technology-preview-released.aspx"&gt;here&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;Thanks,   &lt;br /&gt;Diego&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9917658" width="1" height="1"&gt;</description></item><item><title>Standard generated entity classes in EF4</title><link>http://blogs.msdn.com/diego/archive/2009/09/08/to-pi-or-not-to-pi-with-ef4-that-is.aspx</link><pubDate>Tue, 08 Sep 2009 04:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9892387</guid><dc:creator>divega</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/diego/comments/9892387.aspx</comments><wfw:commentRss>http://blogs.msdn.com/diego/commentrss.aspx?PostID=9892387</wfw:commentRss><wfw:comment>http://blogs.msdn.com/diego/rsscomments.aspx?PostID=9892387</wfw:comment><description>&lt;P&gt;A customer recently asked if there is still any advantage in using the entities that Entity Framework 4 generates by default instead of POCO classes. &lt;/P&gt;
&lt;P&gt;Another way to look at this is: why are non-POCO classes that inherit from System.Data.Objects.DataClasses.EntityObject and use all sort of attributes to specify mapping of properties and relationship still the default in EF4?&lt;/P&gt;
&lt;P&gt;This perspective makes the question more interesting for me, especially given a great portion of the investment we made in EF 4 went into adding support of Persistence Ignorance, and also given that using POCO is my personal preference, and I am aware of all the advantage this has for the evolvability and testability of my code.&lt;/P&gt;
&lt;P&gt;So, let’s look from closer and see what we find. &lt;/P&gt;
&lt;P&gt;&lt;B&gt;Moving from previous versions&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;If you simply diff the entity code generated using the first version with what we generate nowadays, the first thing you will notice is that they haven’t changed much. &lt;/P&gt;
&lt;P&gt;The fact that there aren’t many changes is actually a nice feature for people moving from the previous version to the new version. If you started your project with Visual Studio 2008 SP1 and now you decide to move it to Visual Studio 2010 (i.e. the current beta), it is a good thing that you don’t have to touch your code to get your application running again.&lt;/P&gt;
&lt;P&gt;It is worth mentioning that many of the improvements in the new version of EF (i.e. lazy loading) were designed to work with all kinds of entities, so they didn’t really require changes to the code we generate.&lt;/P&gt;
&lt;P&gt;Even if you later decided to regenerate your model to take advantage of new features (i.e. singularization and foreign key support), you might need to do some renaming, and some things may be simplified, but most things your code do will remain the same.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;New code generation engine&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;As soon as you look under the hood though, you will notice that we actually changed the whole code generation story to be based on &lt;A href="http://msdn.microsoft.com/en-us/library/bb126445(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb126445(VS.100).aspx"&gt;T4&lt;/A&gt; templates. This opens lots of possibilities, from having our customers customize the code to suit their needs, to have us release new templates for entity types optimized for particular scenarios. This last idea is exemplified in the work we have been doing in the &lt;A href="http://blogs.msdn.com/adonet/archive/2009/06/22/feature-ctp-walkthrough-poco-templates-for-entity-framework.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2009/06/22/feature-ctp-walkthrough-poco-templates-for-entity-framework.aspx"&gt;POCO template&lt;/A&gt; and the &lt;A href="http://blogs.msdn.com/adonet/archive/2009/06/22/feature-ctp-walkthrough-self-tracking-entities-for-entity-framework.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2009/06/22/feature-ctp-walkthrough-self-tracking-entities-for-entity-framework.aspx"&gt;Self-Tracking Entities Template&lt;/A&gt; included in the &lt;A href="http://blogs.msdn.com/adonet/archive/2009/06/22/announcing-entity-framework-feature-ctp-1.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2009/06/22/announcing-entity-framework-feature-ctp-1.aspx"&gt;Feature CTP 1&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;At this point, we don't have plans to include templates for generating entities of other kinds in Visual Studio 2010, so the default, EntityObject-based template is the only one that is included “in the box”.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Change tracking and relationship alignment &lt;/B&gt;&lt;/P&gt;
&lt;P&gt;It is also important that default entities enjoy the highest level of functionality in Entity Framework. To begin with, they participate in notification-based change tracking, which is the most efficient. Also, navigation properties on default entities are backed by the same data structures Entity Framework uses to maintain information about relationships, meaning that any change you make is reflected immediately on the navigation properties on both sides. &lt;/P&gt;
&lt;P&gt;By comparison, plain POCO objects do not notify Entity Framework of changes on them, and relationships are usually represented by plain object references and collections that are not synchronized automatically. To work well with POCO, Entity Framework needs to compare snapshots of property values and reconcile changes in linked navigation properties at certain points of a transaction. To that end, we introduced a new DetectChanges method that allows user code to control explicitly when that change detection happens, and we also added an implicit call to it in SaveChanges. &lt;/P&gt;
&lt;P&gt;As an alternative to that, we also introduced POCO Proxies that inject most of the change tracking and relationships management capabilities of default entities into POCO types by the means of inheritance. This kind of POCO Proxies are created only (basically) if you make all properties virtual in the POCO class and, if you need to create a new instance, you invoke the new ObjectContext.CreateObject&amp;lt;T&amp;gt; method.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Again, why is non-POCO still the default?&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;To summarize:&lt;/P&gt;
&lt;P&gt;a. Default code-gen classes provide the easiest path for people moving from the previous version&lt;/P&gt;
&lt;P&gt;b. When creating a model from scratch or from the database, you don’t even need to write the code for the entities themselves&lt;/P&gt;
&lt;P&gt;c. You &lt;B&gt;never&lt;/B&gt; need to worry about invoking DetectChanges or about making sure your code always uses POCO Proxies&lt;/P&gt;
&lt;P&gt;d. Finally, if you really care the most about writing entities yourself, we make it very easy for you to opt-out of code generation and start writing your own POCO classes.&lt;/P&gt;
&lt;P&gt;I hope this information is useful. So, now what kind of entity classes are you going to use?&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9892387" width="1" height="1"&gt;</description></item><item><title>WPF databinding with the POCO Template</title><link>http://blogs.msdn.com/diego/archive/2009/07/26/wpf-databinding-with-the-poco-template.aspx</link><pubDate>Sun, 26 Jul 2009 15:42:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9849173</guid><dc:creator>divega</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/diego/comments/9849173.aspx</comments><wfw:commentRss>http://blogs.msdn.com/diego/commentrss.aspx?PostID=9849173</wfw:commentRss><wfw:comment>http://blogs.msdn.com/diego/rsscomments.aspx?PostID=9849173</wfw:comment><description>&lt;p&gt;The new support for POCO in Entity Framework seeks to enable better ways of coding application domain logic without polluting domain classes with persistence concerns. Persistence Ignorance can in fact improve maintainability, testability and evolvability of an application by making it possible to write domain classes that the contain domain logic and nothing more. &lt;/p&gt;  &lt;p&gt;Persistence isn’t however the only common infrastructure service that might affect how you write your classes. Others, such as databinding and serialization, sometimes require more than POCO types to work really well. &lt;/p&gt;  &lt;p&gt;Disclaimer: I am not trying to enter a debate on whether you should use domain entities directly in databinding and serialization, I am aware of the recommended patterns :)&lt;/p&gt;  &lt;p&gt;For instance, to get databinding to fully work with a domain model, each object and collection type has to implement a number of interfaces for things like change notification, type description, capability negotiation, etc. That said, a decent level of databinding support can be achived with simple POCO types and collection types that implement IList, such as List&amp;lt;T&amp;gt;.&lt;/p&gt;  &lt;p&gt;In the &lt;a href="http://blogs.msdn.com/adonet/archive/2009/06/22/feature-ctp-walkthrough-poco-templates-for-entity-framework.aspx"&gt;POCO Template&lt;/a&gt; that is included in the Entity Framework Feature CTP 1, we use T4 code generation to produce POCO entity classes and a “typed” ObjectContext class based on an Entity Data Model. The POCO Template emits a special collection type named FixupCollection that has the capability to synchronize changes on both sides of a relationship (typically a one-to-many relationship is represented as a collection on the one side, and as a reference in each object of the many side). But as a colleague of mine found today, Since FixupCollection derives from ICollection&amp;lt;T&amp;gt; and not IList&amp;lt;T&amp;gt;, WPF databinding will not work with it in read-write scenarios. &lt;/p&gt;  &lt;p&gt;If you try to bind to a collection emitted by the POCO Template (i.e. in a master-detail form), and the you try to edit it, you will run into this exception message:&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; color: #a31515; font-size: 9.5pt"&gt;'EditItem' is not allowed for this view. &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;The exception indicates that WPF considers that the collection is read-only. &lt;/p&gt;  &lt;p&gt;Here is a way to overcome this:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Extend FixupCollection in a partial class to implement IListSource. &lt;/li&gt;    &lt;li&gt;The implementation of IListSource.GetList has to return a binding list. For instance, I implemented a custom ObservableCollection that has the necessary hooks to update the underlying FixupCollection whenever elements are added or removed. &lt;/li&gt;    &lt;li&gt;Currently, this doesn’t work the other way around. For instance, when entities added or removed in the underlying collection, the ObservableCollection is not updated. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Here is the code:&lt;/p&gt; &lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; color: blue; font-size: 9.5pt"&gt;using&lt;/span&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt; System.Collections.ObjectModel; &lt;/span&gt;&lt;/span&gt;  &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; color: blue; font-size: 9.5pt"&gt;using&lt;/span&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt; System.ComponentModel; &lt;/span&gt;&lt;/span&gt;  &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;     &lt;p&gt;&lt;/p&gt;   &lt;/span&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; color: green; font-size: 9.5pt"&gt;//TODO: update the namespace to match the same as the code-gen        &lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; color: green; font-size: 9.5pt"&gt;//FixupCollection&lt;/span&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt; &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; color: blue; font-size: 9.5pt"&gt;namespace&lt;/span&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt; Model &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;{ &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;partial&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;FixupCollection&lt;/span&gt;&amp;lt;TFrom, TTo&amp;gt; : &lt;span style="color: #2b91af"&gt;IListSource&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; { &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;bool&lt;/span&gt; &lt;span style="color: #2b91af"&gt;IListSource&lt;/span&gt;.ContainsListCollection &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;get&lt;/span&gt; { &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: blue"&gt;false&lt;/span&gt;; } &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&amp;#160; &lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; System.Collections.&lt;span style="color: #2b91af"&gt;IList&lt;/span&gt; &lt;span style="color: #2b91af"&gt;IListSource&lt;/span&gt;.GetList() &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;FixupCollectionBindingList&lt;/span&gt;&amp;lt;TFrom, TTo&amp;gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;); &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;FixupCollectionBindingList&lt;/span&gt;&amp;lt;TFrom, TTo&amp;gt; : &lt;span style="color: #2b91af"&gt;         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ObservableCollection&lt;/span&gt;&amp;lt;TTo&amp;gt; &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; { &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;readonly&lt;/span&gt; &lt;span style="color: #2b91af"&gt;FixupCollection&lt;/span&gt;&amp;lt;TFrom, TTo&amp;gt; _source = &lt;span style="color: blue"&gt;null&lt;/span&gt;; &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; FixupCollectionBindingList(         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;FixupCollection&lt;/span&gt;&amp;lt;TFrom, TTo&amp;gt; source) &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : &lt;span style="color: blue"&gt;base&lt;/span&gt;(source) &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;this&lt;/span&gt;._source = source; &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; InsertItem(&lt;span style="color: blue"&gt;int&lt;/span&gt; index, TTo item) &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _source.Add(item); &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;base&lt;/span&gt;.InsertItem(index, item); &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; RemoveItem(&lt;span style="color: blue"&gt;int&lt;/span&gt; index) &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _source.Remove(&lt;span style="color: blue"&gt;this&lt;/span&gt;[index]); &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;base&lt;/span&gt;.RemoveItem(index); &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;span style="margin-bottom: 0pt" class="MsoNormal"&gt;&lt;span style="line-height: 115%; font-family: consolas; font-size: 9.5pt"&gt;} &lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;&lt;/span&gt;  &lt;p&gt;Hope this helps,&lt;/p&gt;  &lt;p&gt;Diego&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9849173" width="1" height="1"&gt;</description></item><item><title>Beth Massi on Entity Framework + WPF</title><link>http://blogs.msdn.com/diego/archive/2009/07/20/beth-massi-on-entity-framework-wpf.aspx</link><pubDate>Mon, 20 Jul 2009 19:23:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9841867</guid><dc:creator>divega</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/diego/comments/9841867.aspx</comments><wfw:commentRss>http://blogs.msdn.com/diego/commentrss.aspx?PostID=9841867</wfw:commentRss><wfw:comment>http://blogs.msdn.com/diego/rsscomments.aspx?PostID=9841867</wfw:comment><description>&lt;p&gt;I haven’t met &lt;a href="http://blogs.msdn.com/bethmassi/"&gt;Beth&lt;/a&gt; in person but I noticed her awesome &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/07/14/master-detail-data-binding-in-wpf-with-entity-framework.aspx"&gt;blog posts and videos&lt;/a&gt; focused on using Entity Framework with WPF. Very useful stuff!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9841867" width="1" height="1"&gt;</description></item><item><title>Rowan on Entity Framework Events and Alex’s Tips</title><link>http://blogs.msdn.com/diego/archive/2009/07/07/rowan-on-entity-framework-events-and-alex-s-tips.aspx</link><pubDate>Tue, 07 Jul 2009 22:30:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9823076</guid><dc:creator>divega</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/diego/comments/9823076.aspx</comments><wfw:commentRss>http://blogs.msdn.com/diego/commentrss.aspx?PostID=9823076</wfw:commentRss><wfw:comment>http://blogs.msdn.com/diego/rsscomments.aspx?PostID=9823076</wfw:comment><description>&lt;p&gt;I don’t post much on my blog lately (too busy working on Entity Framework for .NET 4!), but &lt;a href="http://romiller.com/Home/tabid/36/EntryID/51/Default.aspx"&gt;this post&lt;/a&gt; from my teammate Rowan struck me as something that would help lots of customers, so I wanted to link to it. It explains basically everything you need to know about events available in the Object Services API of Entity Framework.&lt;/p&gt;  &lt;p&gt;While I am here, the &lt;a href="http://blogs.msdn.com/alexj/archive/tags/Tips/default.aspx"&gt;tips series in my other teammate Alex James’ blog&lt;/a&gt; probably don’t need much publicity from me, but they are an awesome resource for customers.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9823076" width="1" height="1"&gt;</description></item><item><title>Third post about POCO, first post about Code Only</title><link>http://blogs.msdn.com/diego/archive/2009/06/10/third-post-about-poco-first-post-about-code-only.aspx</link><pubDate>Thu, 11 Jun 2009 01:28:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9725170</guid><dc:creator>divega</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/diego/comments/9725170.aspx</comments><wfw:commentRss>http://blogs.msdn.com/diego/commentrss.aspx?PostID=9725170</wfw:commentRss><wfw:comment>http://blogs.msdn.com/diego/rsscomments.aspx?PostID=9725170</wfw:comment><description>&lt;p&gt;It is always busy here with all the improvements we are doing in Entity Framework to make your code work better with it. That is why I haven’t been posting to my blog much in the last months. Today however, there are two important posts from people that sit very close to me, so I am going to link to them. &lt;/p&gt;  &lt;p&gt;Faisal posted the &lt;a href="http://blogs.msdn.com/adonet/archive/2009/06/10/poco-in-the-entity-framework-part-3-change-tracking-with-poco.aspx"&gt;third part in a series on the POCO experience with EF4&lt;/a&gt;. His post delves into the details of how snapshot change tracking compares with notification based change tracking and on some of the API considerations for it.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/alexj/"&gt;Alex&lt;/a&gt;, who sits in my office (although he likes to think I sit in his :)) made the &lt;a href="http://blogs.msdn.com/efdesign/archive/2009/06/10/code-only.aspx"&gt;first post about the Code Only experience&lt;/a&gt; we are working on. I like to think of Code Only as “POCO on steroids”, because it not only gives you the right level of decoupling between your domain classes and the persistence framework, but it also puts mapping artifacts out of the way. I am especially fond of the way you can customize mapping using LINQ queries, although that feature is not going to be included in the first preview.&lt;/p&gt;  &lt;p&gt;Please go read the posts, play with the bits (you will need to wait a few weeks to play with code-only) and tell us what you think!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9725170" width="1" height="1"&gt;</description></item><item><title>Server queries and identity resolution</title><link>http://blogs.msdn.com/diego/archive/2009/02/24/server-queries-and-identity-resolution.aspx</link><pubDate>Wed, 25 Feb 2009 00:02:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9443162</guid><dc:creator>divega</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/diego/comments/9443162.aspx</comments><wfw:commentRss>http://blogs.msdn.com/diego/commentrss.aspx?PostID=9443162</wfw:commentRss><wfw:comment>http://blogs.msdn.com/diego/rsscomments.aspx?PostID=9443162</wfw:comment><description>&lt;p&gt;I answered a &lt;a href="http://connect.microsoft.com/"&gt;Connect&lt;/a&gt; issue today that deals with a very common expectation for users of systems like Entity Framework and LINQ to SQL. The issue was something like this:&lt;/p&gt;  &lt;p&gt;&lt;em&gt;When I run a query, I expect entities that I have added to the context and that are still not saved but match the predicate of the query to show up in the results.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Reality is that Entity Framework queries are always server queries: all queries, LINQ or Entity SQL based, are translated to the database server’s native query language and then evaluated exclusively on the server. &lt;/p&gt;  &lt;div style="border-bottom-style: ridge; padding-bottom: 8px; border-right-style: ridge; padding-left: 8px; padding-right: 8px; border-top-style: ridge; border-left-style: ridge; padding-top: 8px"&gt;&lt;em&gt;Note: LINQ to SQL actually relaxes this principle in two ways:&lt;/em&gt;     &lt;p&gt;&lt;em&gt;1. Identity-based queries are resolved against the local identity map. For instance, the following query shall not hit the data store:&lt;/em&gt;&lt;/p&gt;    &lt;blockquote&gt;     &lt;p&gt;&lt;/p&gt;      &lt;div class="codeblock"&gt;var c = context.Customers        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; .Where(c =&amp;gt; c.CustomerID == &amp;quot;ALFKI&amp;quot;);&lt;/div&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/blockquote&gt;    &lt;p&gt;&lt;em&gt;2. The outermost projection of the query is evaluated on the client. For instance, the following query will create a server query that projects CustomerID and will invoke a client-side WriteLineAndReturn method as code iterates through results:&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;/p&gt;    &lt;blockquote&gt;     &lt;div class="codeblock"&gt;var q = context.Customers        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; .Select(c =&amp;gt; WriteLineAndReturn(c.CustomerID));&lt;/div&gt;   &lt;/blockquote&gt;   &lt;em&gt;But this does not affect the behavior explained in this post.&lt;/em&gt;&lt;/div&gt;  &lt;p&gt;In sum, Entity Framework does not include a client-side or hybrid query processor.&lt;/p&gt;  &lt;h4&gt;&lt;strong&gt;MergeOption and Identity resolution&lt;/strong&gt;&lt;/h4&gt;  &lt;p&gt;There are chances that you have seen unsaved modifications in entities included in the results of queries. This is due to the fact that for tracked queries (i.e. if the query’s MergeOption is set to a value different from NoTracking) Entity Framework performs “identity resolution”. &lt;/p&gt;  &lt;p&gt;The process can be simply explained like this:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;The identity of each incoming entity is determined by building the corresponding EntityKey. &lt;/li&gt;    &lt;li&gt;The ObjectStateManager is looked up for an entity already present that has a matching EntityKey. &lt;/li&gt;    &lt;li&gt;If an entity with the same identity is already being tracked, the data coming from the server and the data already in the state manager are merged according to the MergeOption of the query. &lt;/li&gt;    &lt;li&gt;In the default case, MergeOption is AppendOnly, which means that the data of the entity in the state manager is left intact and is returned as part of the query results. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;However, membership of an entity in the results of a given query is decided exclusively based on the state existing on the server. In this example, for instance, what will the query get?:&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;div class="codeblock"&gt;var customer1 = Customer.CreateCustomer(1, &amp;quot;Tiger&amp;quot;);    &lt;br /&gt;var customer2 = Customer.CreateCustomer(2, &amp;quot;Zombie&amp;quot;);     &lt;br /&gt;context.SaveChanges();     &lt;br /&gt;customer1.LastName = &amp;quot;Zebra&amp;quot;;     &lt;br /&gt;var customer3 = Customer.CreateCustomer(100, &amp;quot;Zorro&amp;quot;);     &lt;br /&gt;context.AddObject(&amp;quot;Customers&amp;quot;, customer3);     &lt;br /&gt;context.DeleteObject(customer2);     &lt;br /&gt;var customerQuery = context.Customers     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; .Where(c =&amp;gt; c.LastName.StartsWith(&amp;quot;Z&amp;quot;));     &lt;br /&gt;foreach(var customer in customerQuery)     &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; if (customer == customer1)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Console.WriteLine(c.LastName);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;}&lt;/div&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;The answer is:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;The modified entity customer1 won’t show up in the query because its LastName is still Tiger on the database. &lt;/li&gt;    &lt;li&gt;The deleted entity customer2 will be returned by the query, although it is a deleted entity already, because it still exists in the database. &lt;/li&gt;    &lt;li&gt;The new entity customer3 won’t make it, because it only exists in the local ObjectStateManager and not in the database. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;This behavior is by design and you need to be aware of it when writing your application. &lt;/p&gt;  &lt;p&gt;Put in some other way, if the units of work in your application follow a pattern in which they query first, then make modifications to entities and finally save them, discrepancies between query results and the contents of the ObjectSateManager cannot be observed. &lt;/p&gt;  &lt;p&gt;But as soon as queries are interleaved with modifications there is a chance that the server won’t contain an entity that exist in the state manager only and that that would match the predicate of the query. Those entities won’t be returned as part of the query.&lt;/p&gt;  &lt;p&gt;Notice that the chances that this happens has to do with how long lived is the Unit of Work in your application (i.e. how much does it take from the initial query to the call to SaveChanges).&lt;/p&gt;  &lt;p&gt;Hope this helps,    &lt;br /&gt;Diego&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9443162" width="1" height="1"&gt;</description></item><item><title>EntityDataSource and Bind: What are those square brackets?</title><link>http://blogs.msdn.com/diego/archive/2009/02/02/entitydatasource-and-bind-what-are-those-square-brackets.aspx</link><pubDate>Mon, 02 Feb 2009 09:25:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9389647</guid><dc:creator>divega</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/diego/comments/9389647.aspx</comments><wfw:commentRss>http://blogs.msdn.com/diego/commentrss.aspx?PostID=9389647</wfw:commentRss><wfw:comment>http://blogs.msdn.com/diego/rsscomments.aspx?PostID=9389647</wfw:comment><description>&lt;p&gt;This post is about a small issue that I have seen in the &lt;a href="http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/threads/"&gt;forums&lt;/a&gt; and that arises often in cases in which EntityDataSource is used in combination with bound controls that use templates, like FormsView or a GridView with template based columns. &lt;/p&gt;  &lt;p&gt;If you can create your page correctly, simply using the different drag &amp;amp; drop features and context menus provided by the design surface. However, in the end, some Bind expressions will get enclosed in square brackets that produce compile or run-time errors, then your code may look like this:&lt;/p&gt;  &lt;div class="codeblock"&gt;&amp;lt;EditItemTemplate&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;asp:DropDownList ID=&amp;quot;CategoryDropDownList&amp;quot; runat=&amp;quot;server&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DataSourceID=&amp;quot;CategoryDataSource&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DataTextField=&amp;quot;CategoryName&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DataValueField=&amp;quot;CategoryID&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SelectedValue='&amp;lt;%# &lt;strong&gt;Bind(&amp;quot;&lt;font color="#800000"&gt;[Category.CategoryID]&lt;/font&gt;&amp;quot;)&lt;/strong&gt; %&amp;gt;'&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/asp:DropDownList&amp;gt;     &lt;br /&gt;&amp;lt;/EditItemTemplate&amp;gt; &lt;/div&gt;  &lt;p&gt;This annoyance may keep you blocked until you realize how simple the workaround is: just remove the square brackets! &lt;/p&gt;  &lt;p&gt;People that watched my video &lt;a href="http://www.asp.net/learn/3.5-videos/video-500.aspx"&gt;here&lt;/a&gt;, may have noticed that I had to remove the square brackets manually around minute 8:10. I wish I had blogged about it then, but it wasn’t clear at the time I recorded that video that the issue would still be there in the RTM version.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Here is a short explanation:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;In order to adapt entity objects that do not have foreign key properties to work better with ASP.NET databinding, we decided to wrap each entity returned with a databinding wrapper object that, among other things, flattens the members of EntityKeys in related entities (for more details on how and why the EntityDataSource returns wrapped entities you can go &lt;a href="http://blogs.msdn.com/diego/archive/2008/05/13/entitydatasource-to-wrap-or-not-to-wrap.aspx"&gt;here&lt;/a&gt;).&lt;/p&gt;  &lt;p&gt;The name of flattened reference keys are usually composed by the corresponding navigation property, plus the name of the property in the related end. For instance, in a Product, the key of the associated Category, will be exposed as “Category.CategoryID”. We decided to use dots to delimit the parts of the name because that plays well and is consistent with the use of dots in most programming languages, and also in Eval expressions, like the one used in the following code: &lt;/p&gt;  &lt;div class="codeblock"&gt;&amp;lt;ItemTemplate&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;asp:Label ID=&amp;quot;CategoryLabel&amp;quot; runat=&amp;quot;server&amp;quot;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Text='&amp;lt;%# Eval(&amp;quot;&lt;strong&gt;&lt;font color="#800000"&gt;Category.CategoryName&lt;/font&gt;&lt;/strong&gt;&amp;quot;) %&amp;gt;'&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/asp:Label&amp;gt;     &lt;br /&gt;&amp;lt;/ItemTemplate&amp;gt; &lt;/div&gt;  &lt;p&gt;The problem is that for the particular case of Bind (often used in template based databound controls to perform two-way databinding) the design time component of ASP.NET will catch property names that contain dots, and it will try to escape them by surrounding them with square brackets (leading to ta Bind expression of the form “[Categories.CategoryID]”). &lt;/p&gt;  &lt;p&gt;Unfortunately, the rest of the ASP.NET components which need to evaluate the binding expression are actually not capable of parsing the square brackets escaping notation (i.e. for DataBinder.Eval() the brackets actually indicate that a lookup in an indexed property is necessary, and there is no indexed property in this case). &lt;/p&gt;  &lt;p&gt;Given that the EntityDataSource in fact exposes property descriptors that contain dots in their names, the escaping is unnecessary. So, next time you find this issue, just remove the square brackets.&lt;/p&gt;  &lt;p&gt;The good news is that the issue will be fixed in the next release. &lt;/p&gt;  &lt;p&gt;Hope this helps!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9389647" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/diego/archive/tags/EntityDataSource/default.aspx">EntityDataSource</category></item><item><title>Exposing EDM and database server functions to LINQ</title><link>http://blogs.msdn.com/diego/archive/2008/10/09/exposing-edm-and-database-server-functions-to-linq.aspx</link><pubDate>Thu, 09 Oct 2008 06:36:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8992402</guid><dc:creator>divega</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/diego/comments/8992402.aspx</comments><wfw:commentRss>http://blogs.msdn.com/diego/commentrss.aspx?PostID=8992402</wfw:commentRss><wfw:comment>http://blogs.msdn.com/diego/rsscomments.aspx?PostID=8992402</wfw:comment><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/alexj/"&gt;Alex&lt;/a&gt; published today a description &lt;a href="http://blogs.msdn.com/meek/"&gt;Colin&lt;/a&gt; and I wrote on a new feature the team has been working on for LINQ to Entities. &lt;/p&gt;  &lt;p&gt;Beyond all technicalities, it is a very simple and attribute-based way of exposing any arbitrary server-side function to LINQ. It goes beyond what LINQ to SQL does with SqlMethods and it leverages our metadata system so that you don't have to specify the full mapping of parameters in the attribute. &lt;/p&gt;  &lt;p&gt;The post itself may be a little boring ;), but the scenarios it enables are quite impressive.&lt;/p&gt;  &lt;p&gt;Read more &lt;a href="http://blogs.msdn.com/efdesign/archive/2008/10/08/edm-and-store-functions-exposed-in-linq.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;Update: I remembered today that Kati Dimitrova and Sheetal Gupta also contributed to the document.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8992402" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/diego/archive/tags/LINQ+to+Entities/default.aspx">LINQ to Entities</category></item><item><title>Quick tips for Entity Framework Databinding</title><link>http://blogs.msdn.com/diego/archive/2008/10/09/quick-tips-for-entity-framework-databinding.aspx</link><pubDate>Thu, 09 Oct 2008 06:26:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8992394</guid><dc:creator>divega</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/diego/comments/8992394.aspx</comments><wfw:commentRss>http://blogs.msdn.com/diego/commentrss.aspx?PostID=8992394</wfw:commentRss><wfw:comment>http://blogs.msdn.com/diego/rsscomments.aspx?PostID=8992394</wfw:comment><description>&lt;p&gt;One of our customers asked &lt;a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3971858&amp;amp;SiteID=1"&gt;this&lt;/a&gt; question yesterday on the Entity Framework forums. There were a few details missing and so I am not completely sure I got the question right. But I think it is about an issue I have heard quite a bit, and so I think it may be useful to share my answer here for others.&lt;/p&gt;  &lt;p&gt;Given this simple line of code (i.e. in a WinForms application):&lt;/p&gt;  &lt;div class="codeblock"&gt;grid.DataSource = someQuery; &lt;/div&gt;  &lt;p&gt;Several things will happening under the hood:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Databinding finds that ObjectQuery&amp;lt;T&amp;gt; implements the IListSource interface, then it calls IListSource.GetList() on it, to obtain a binding list (an internal object that implements IBindingList and some other well-known interfaces that databound controls know how to communicate with) &lt;/li&gt;    &lt;li&gt;GetList() gets the query executed and it copies the contents of the resulting ObjectResult object to the binding list &lt;/li&gt;    &lt;li&gt;The new binding list is finally passed to the databound control &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;When a binding list is created this way from a tracked query (i.e. MergeOption in the query is set to anything but NoTracking), there are several other interesting details in the behavior: &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;em&gt;&lt;strong&gt;Changes made to entities in the binding list will get noticed by the state manger. &lt;/strong&gt;&lt;/em&gt;Therefore changes will be saved to the database when SaveChanges is invoked on the tracking ObjectContext &lt;/li&gt;    &lt;li&gt;&lt;em&gt;&lt;strong&gt;Additions of new entities to the context will not result in the new entities being added automatically to a binding list (this is a common expectation).&lt;/strong&gt; &lt;/em&gt;Whether an entity belongs to a binding list is decided at the time the binding list is created. If we wanted to do something different (i.e. have the binding list get new objects added to the context automatically), we would hit some considerable obstacles:       &lt;ul&gt;       &lt;li&gt;The binding list does not remember which filter condition was used in the query. &lt;/li&gt;        &lt;li&gt;Even if it did, our queries are server queries, expressed in either ESQL or LINQ, but always translated to server queries and then expressed in terms of the current values on the server. &lt;/li&gt;        &lt;li&gt;Even for LINQ queries, we cannot assume that the same query will have equivalent behavior while querying in-memory objects when compared to the same query translated to the native SQL of the database. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;&lt;em&gt;&lt;strong&gt;As a consequence of #2: You can have multiple binding lists based on the same EntitySet with overlapping or disjoint sets of entities. &lt;/strong&gt;&lt;/em&gt;You can use different queries (or even from the same query, but with different parameters) to get a different set of entities in each binding list.&lt;strong&gt; &lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;&lt;em&gt;Deletion of entities from the context will result in the deleted entity being removed from all binding lists that contain it.&lt;/em&gt;&lt;/strong&gt; The principle behind this is that the binding list is a window into the &amp;quot;current state of affairs&amp;quot; in the state manager. Even if we don't know if a new entity belongs into a binding list, we do know when it doesn't belong anymore, because it has been deleted. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;&lt;em&gt;A binding list has its own Add() method you can use.&lt;/em&gt; &lt;/strong&gt;If you could get a reference to one of our binding lists you could “manually” add new entities to the binding list, and the entity you add will also be added to the context automatically, the same as if it had invoked&amp;#160; AddObject() on the context. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;All these facts, especially #5, warrant me to give you a couple of tips:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;If you are interested in getting a reference to the binding list directly (i.e. to use its Add method), you can do something like this:      &lt;div class="codeblock"&gt;&lt;span class="keyword"&gt;var&lt;/span&gt; bindingList = ((&lt;span class="type"&gt;IListSource&lt;/span&gt;)query).GetList() &lt;span class="keyword"&gt;as&lt;/span&gt; &lt;span class="type"&gt;IBindingList&lt;/span&gt;;&lt;/div&gt; There is a more convenient ToBindingList() extension method included in the &lt;a href="http://code.msdn.com/efextensions"&gt;EFExtensions&lt;/a&gt; you may want to take a look at. &lt;/li&gt;    &lt;li&gt;If you are not interested in getting the reference to the binding list for yourself, and you are using databinding directly against a query as in the sample at the top of this post, you should know that WinForms will call IListSource.GetList() twice, causing the query to be executed on the server twice! The recommendation then is to bind to the results, rather than the query, using code similar to this:      &lt;div class="codeblock"&gt;grid.DataSource = someQuery.Execute(&lt;span class="type"&gt;MergeOption&lt;/span&gt;.AppendOnly); &lt;/div&gt; In this case, since the resulting ObjectResult acts as a foward-only, enumerate-once cursor, its implementation of IListSource.GetList() is different from the one in the query: the call will consume the results (i.e. it will iterate through the whole results) and will cache the binding list in the ObjectResult instance. All subsequent calls to IListSource.GetList() will return the same binding list. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;We have a few ideas around things we may improve in future versions. Some of them you may be able to guess from this explanation. But I will save that for another post...&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8992394" width="1" height="1"&gt;</description></item><item><title>Jarek publishes his excellent Entity Framework POCO Adapter</title><link>http://blogs.msdn.com/diego/archive/2008/09/09/jarek-publishes-his-excellent-entity-framework-poco-adapter.aspx</link><pubDate>Tue, 09 Sep 2008 20:50:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8937106</guid><dc:creator>divega</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/diego/comments/8937106.aspx</comments><wfw:commentRss>http://blogs.msdn.com/diego/commentrss.aspx?PostID=8937106</wfw:commentRss><wfw:comment>http://blogs.msdn.com/diego/rsscomments.aspx?PostID=8937106</wfw:comment><description>&lt;p&gt;I have been back from vacation for some time but I haven't had time to post anything (i.e. I was on vacation the day Entity Framework went RTM in .NET 3.5 SP1!). &lt;/p&gt;  &lt;p&gt;Finally, something happened that I cannot wait to talk about. &lt;/p&gt;  &lt;p&gt;Jarek and I went discussing how persistence ignorant classes could be supported by building a layer on top of the EF v1 API for a long time. &lt;/p&gt;  &lt;p&gt;He finally figured out a good way to do it. The result is this sample that wraps Entity Framework APIs and uses simple code-generation to create &amp;quot;adapters&amp;quot; and &amp;quot;proxies&amp;quot; for your POCO classes:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://code.msdn.microsoft.com/EFPocoAdapter"&gt;Entity Framework POCO Adapter&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can read Jarek's &lt;a href="http://blogs.msdn.com/jkowalski/archive/2008/09/09/persistence-ignorance-poco-adapter-for-entity-framework-v1.aspx"&gt;blog post&lt;/a&gt; explaining it all. &lt;/p&gt;  &lt;p&gt;We hope people will find it interesting and will send useful feedback that can help us improve the core product.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8937106" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/diego/archive/tags/Entity+Framework+Toolkits+_2600_amp_3B00_+Extensions/default.aspx">Entity Framework Toolkits &amp;amp; Extensions</category><category domain="http://blogs.msdn.com/diego/archive/tags/POCO/default.aspx">POCO</category></item><item><title>Sample Entity Framework Provider for Oracle now Available</title><link>http://blogs.msdn.com/diego/archive/2008/06/24/sample-entity-framework-provider-for-oracle-now-available.aspx</link><pubDate>Tue, 24 Jun 2008 03:03:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8644381</guid><dc:creator>divega</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/diego/comments/8644381.aspx</comments><wfw:commentRss>http://blogs.msdn.com/diego/commentrss.aspx?PostID=8644381</wfw:commentRss><wfw:comment>http://blogs.msdn.com/diego/rsscomments.aspx?PostID=8644381</wfw:comment><description>&lt;p&gt;This new sample builds on top of System.Data.OracleClient and showcases some techniques a provider writer targeting databases different from SQL Server can use. &lt;/p&gt;  &lt;p&gt;The code is not meant for production, just a sample directed to provider writers. It has also a few limitations related both to SP1 beta bits and with types not supported in OracleClient. &lt;/p&gt;  &lt;p&gt;For more details, read &lt;a href="http://blogs.msdn.com/jkowalski/archive/2008/06/23/sample-entity-framework-provider-for-oracle.aspx"&gt;Jarek's post&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;You can download the source code from our &lt;a href="http://code.msdn.microsoft.com/adonetefx"&gt;home page in Code Gallery&lt;/a&gt;. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8644381" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/diego/archive/tags/Entity+Framework+Samples/default.aspx">Entity Framework Samples</category></item><item><title>Entity Framework Sample Provider Updated for SP1 Beta</title><link>http://blogs.msdn.com/diego/archive/2008/06/03/entity-framework-sample-provider-updated-for-sp1-beta.aspx</link><pubDate>Tue, 03 Jun 2008 20:18:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8571819</guid><dc:creator>divega</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/diego/comments/8571819.aspx</comments><wfw:commentRss>http://blogs.msdn.com/diego/commentrss.aspx?PostID=8571819</wfw:commentRss><wfw:comment>http://blogs.msdn.com/diego/rsscomments.aspx?PostID=8571819</wfw:comment><description>&lt;p&gt;Just to get the news out: The updated version of the Entity Framework Sample Provider that is compatible with .NET 3.5 SP1 Beta is now available in our &lt;a href="http://code.msdn.microsoft.com/adonetefx"&gt;Code Gallery page&lt;/a&gt;. From the description:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;The Sample Provider wraps System.Data.SqlClient and demonstrates the new functionality an ADO.NET Provider needs to implement in order to support the ADO.NET Entity Framework&lt;/p&gt;    &lt;ul&gt;     &lt;ul&gt;       &lt;li&gt;Provider Manifest &lt;/li&gt;        &lt;li&gt;EDM Mapping for Schema Information &lt;/li&gt;        &lt;li&gt;SQL Generation &lt;/li&gt;     &lt;/ul&gt;   &lt;/ul&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;strong&gt;Update: &lt;/strong&gt;for more details on provider API changes since the Beta3 release, you can read Jarek's post &lt;a href="http://blogs.msdn.com/jkowalski/archive/2008/06/02/entity-framework-sample-provider-for-visual-studio-2008-sp1-beta-is-online.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8571819" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/diego/archive/tags/Entity+Framework+Samples/default.aspx">Entity Framework Samples</category></item><item><title>EntityDataSource's flattening of complex type properties</title><link>http://blogs.msdn.com/diego/archive/2008/05/24/entitydatasource-s-flattening-of-complex-type-properties.aspx</link><pubDate>Sat, 24 May 2008 20:11:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8548086</guid><dc:creator>divega</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/diego/comments/8548086.aspx</comments><wfw:commentRss>http://blogs.msdn.com/diego/commentrss.aspx?PostID=8548086</wfw:commentRss><wfw:comment>http://blogs.msdn.com/diego/rsscomments.aspx?PostID=8548086</wfw:comment><description>&lt;p&gt;I explained a few days ago the rules of wrapping in &lt;a href="http://blogs.msdn.com/diego/archive/2008/05/13/entitydatasource-to-wrap-or-not-to-wrap.aspx"&gt;this blog post&lt;/a&gt;. But why do we wrap after all?&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.thedatafarm.com/blog"&gt;Julie&lt;/a&gt; &lt;a href="http://forums.microsoft.com/Forums/ShowPost.aspx?PostID=3395595&amp;amp;SiteID=1&amp;amp;mode=1"&gt;asked&lt;/a&gt; for some details today in the forums. I think the answer is worth of a blog post. &lt;/p&gt;  &lt;p&gt;In ASP.NET there are different ways of specifying which property a databound control binds to: Eval() Bind(), BoundField.DataField, ListControl.DataTextField, etc. In general, they behave differently. &lt;/p&gt;  &lt;p&gt;The flattening we did on EntityDataSource is an attempt to make the properties that are exposed by EDM entities available for 2-way databinding in most of those cases. &lt;/p&gt;  &lt;p&gt;For instance, for a customer that has a complex property of type Address, we provide a property descriptor for customer.Address, and also for customer.Address.Street, customer.Address.Number, etc.&lt;/p&gt;  &lt;p&gt;At runtime, in the case of a control binding to Eval(&amp;#8220;Address.Street&amp;#8221;) from a customer, Eval will use the property descriptor corresponding to Address, and it will drill down on it to extract the value of the Street property on it. &lt;/p&gt;  &lt;p&gt;A grid column of a BoundField derived type with DataField = &amp;#8220;Address.Street&amp;#8221; will work differently: it will just look for a property descriptor in the data item with a name as &amp;#8220;Address.Street&amp;#8221;. In fact, EntityDataSource is the first DataSource control that I know off that will provide such a thing. &lt;/p&gt;  &lt;p&gt;Bind(&amp;#8220;Address.Street&amp;#8221;) will work in a similar fashion to Eval() when reading the properties into the data bound control, but will act a little bit more like BoundField when sending back changes to the DataSource.&lt;/p&gt;  &lt;p&gt;There are a few cases in which the behavior is not any of the above and hence you end up with a control that cannot have access to a complex type&amp;#8217;s properties. You can expect us to work closely with the ASP.NET team in making the experience smoother in future versions. But for the time being, what you can do is create an explicit projection of the properties. For instance, in Entity SQL:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; font-family: consolas; mso-bidi-font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;SELECT&lt;/span&gt; c&lt;span style="color: gray"&gt;.&lt;/span&gt;ContactId&lt;span style="color: gray"&gt;,&lt;/span&gt; c&lt;span style="color: gray"&gt;.&lt;/span&gt;Address&lt;span style="color: gray"&gt;.&lt;/span&gt;Street &lt;span style="color: blue"&gt;AS&lt;/span&gt; Street&amp;#160; &lt;br /&gt;&amp;#160; &lt;/span&gt;&lt;span style="font-size: 10pt; line-height: 115%; font-family: consolas; mso-bidi-font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;FROM&lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&amp;#160; &lt;/span&gt;Northwind&lt;span style="color: gray"&gt;.&lt;/span&gt;Customers &lt;span style="color: blue"&gt;AS&lt;/span&gt; c&lt;/span&gt;&lt;span style="font-family: consolas"&gt;     &lt;p&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;I think it is worthy of mentioning: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Remember flattening of complex properties only happen under certain conditions (see &lt;a href="http://blogs.msdn.com/diego/archive/2008/05/13/entitydatasource-to-wrap-or-not-to-wrap.aspx"&gt;wrapping&lt;/a&gt;). &lt;/li&gt;    &lt;li&gt;We worked very closely with the &lt;a href="http://www.asp.net/dynamicdata/"&gt;ASP.NET Dynamic Data&lt;/a&gt; in this release, to enable their technology to work EDM through the EntityDataSource. I think it is very worthy of trying. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Hope this helps.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8548086" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/diego/archive/tags/EntityDataSource/default.aspx">EntityDataSource</category><category domain="http://blogs.msdn.com/diego/archive/tags/Entity+Framework+Databinding/default.aspx">Entity Framework Databinding</category></item><item><title>Entity Framework Extensions Project Update</title><link>http://blogs.msdn.com/diego/archive/2008/05/14/entity-framework-extensions-project-update.aspx</link><pubDate>Wed, 14 May 2008 05:10:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8502476</guid><dc:creator>divega</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/diego/comments/8502476.aspx</comments><wfw:commentRss>http://blogs.msdn.com/diego/commentrss.aspx?PostID=8502476</wfw:commentRss><wfw:comment>http://blogs.msdn.com/diego/rsscomments.aspx?PostID=8502476</wfw:comment><description>&lt;p&gt;Just a couple of links: &lt;/p&gt;  &lt;p&gt;Colin posted a &lt;a href="http://code.msdn.com/efextensions"&gt;refresh&lt;/a&gt; today today that is compatible with .NET 3.5 SP1 Beta and includes some optimizations for the materializer using dynamic methods. Here is &lt;a href="http://blogs.msdn.com/meek/archive/2008/05/13/using-linq-expressions-to-generate-dynamic-methods-ii.aspx"&gt;his post&lt;/a&gt; about it. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8502476" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/diego/archive/tags/Entity+Framework+Toolkits+_2600_amp_3B00_+Extensions/default.aspx">Entity Framework Toolkits &amp;amp; Extensions</category></item></channel></rss>