<?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>Beth Massi - Sharing the goodness that is VB : WPF</title><link>http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx</link><description>Tags: WPF</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>XAML Power Toys Released for Visual Studio 2010</title><link>http://blogs.msdn.com/bethmassi/archive/2009/10/26/xaml-power-toys-released-for-visual-studio-2010.aspx</link><pubDate>Mon, 26 Oct 2009 23:25:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9913239</guid><dc:creator>Beth Massi</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9913239.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9913239</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9913239</wfw:comment><description>&lt;p&gt;I finally made my way back home from Europe and I’m still digging through all my email, newsletters, feeds, etc. But one of the items that grabbed my attention is this week &lt;a href="http://karlshifflett.wordpress.com/" target="_blank"&gt;Karl Shifflett&lt;/a&gt; released updated XAML Power Tools for Visual Studio 2008 as well as a new set for &lt;a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" target="_blank"&gt;Visual Studio 2010&lt;/a&gt;:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;&lt;a href="http://karlshifflett.wordpress.com/2009/10/25/xaml-power-toys-for-visual-studio-2008-v5-0-0-1-released/" target="_blank"&gt;Updated: XAML Power Toys for Visual Studio 2008&lt;/a&gt;&lt;/strong&gt; v5.0.0001 &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;&lt;a href="http://karlshifflett.wordpress.com/2009/10/25/xaml-power-toys-for-visual-studio-2010-beta2/" target="_blank"&gt;New: XAML Power Toys for Visual Studio 2010 Beta2&lt;/a&gt;&lt;/strong&gt; v5.1.0001 - same features as the 2008 version above for Beta2.&amp;#160; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;&lt;a href="http://karlshifflett.wordpress.com/2009/10/25/xaml-power-toys-for-visual-studio-2010-beta2-cider-designer/" target="_blank"&gt;New: XAML Power Toys for Visual Studio 2010 Beta2 for Cider&lt;/a&gt;&lt;/strong&gt;&lt;u&gt;&lt;/u&gt; v1.0 - new product for the WPF Designer&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;If you’re not familiar with these tools, XAML Power Toys are Visual Studio Add-Ins that makes WPF &amp;amp; Silverlight developers much more productive especially for Line of Business applications. They contain form generation tools, Grid tools,&amp;#160; DataForm, DataGrid and ListView generation tools that really shorten the time it takes to lay out UI controls on a WPF form. Thanks Karl!&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9913239" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2010/default.aspx">VS2010</category></item><item><title>WPF In-Depth with Billy Hollis</title><link>http://blogs.msdn.com/bethmassi/archive/2009/10/12/wpf-in-depth-with-billy-hollis.aspx</link><pubDate>Mon, 12 Oct 2009 20:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9906279</guid><dc:creator>Beth Massi</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9906279.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9906279</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9906279</wfw:comment><description>&lt;P&gt;If you’re up in Redmond, the .&lt;A href="http://dotnetda.org/wp/2009/10/10/netda-meeting-10-12-09-wpf-in-depth-with-billy-hollis/" target=_blank mce_href="http://dotnetda.org/wp/2009/10/10/netda-meeting-10-12-09-wpf-in-depth-with-billy-hollis/"&gt;NET Developers Association has a very special guest&lt;/A&gt; for their meeting tonight. &lt;/P&gt;
&lt;P&gt;&lt;A href="http://dotnetmasters.com/" target=_blank mce_href="http://dotnetmasters.com/"&gt;Billy Hollis&lt;/A&gt; will be speaking on WPF showing off a real business application he developed. Billy has a very “practical programmer” style that I always enjoy. He’s also an expert on WPF so this meeting is bound to be informative and fun. Hope you can make it out to campus tonight. The meeting starts at 7pm in the Building 40 cafe. &lt;A href="http://dotnetda.org/wp/directions/" target=_blank mce_href="http://dotnetda.org/wp/directions/"&gt;Check out the .NETDA site for directions&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Meeting details….&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Topic:&lt;/EM&gt; &lt;STRONG&gt;WPF In-Depth: Walkthrough a Real World WPF App&lt;/STRONG&gt; &lt;BR&gt;The StaffLynx application, developed by a team led by Billy Hollis, has been acclaimed for using WPF technologies in a business-oriented software system. In this session, Billy will cover the basic architecture of this application, highlighting architectural differences from previous generations:&amp;nbsp; layered client design, service-based data access, and advanced UI capabilities. He will show how critical pieces are constructed, including novel coding concepts in WPF and XAML. Then he’ll discuss the design and prototyping process, show various prototypes with analysis of their strengths and weaknesses, and cover lessons learned from that process.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Speaker:&lt;/EM&gt; &lt;A href="http://dotnetmasters.com/" mce_href="http://dotnetmasters.com/"&gt;&lt;STRONG&gt;Billy Hollis&lt;/STRONG&gt;&lt;/A&gt; &lt;BR&gt;Billy Hollis is an author and software developer from Nashville, Tennessee. Billy is co-author of the first book ever published on Visual Basic .NET, VB .NET Programming on the Public Beta. He has written many articles, and is a frequent speaker at conferences. He is the Regional Director of Developer Relations in Nashville for Microsoft, and runs a consulting company focusing on Microsoft .NET.&lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9906279" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Community/default.aspx">Community</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category></item><item><title>New “How Do I” Videos Released on Entity Framework &amp; WPF</title><link>http://blogs.msdn.com/bethmassi/archive/2009/08/26/new-how-do-i-videos-released-on-entity-framework-wpf.aspx</link><pubDate>Wed, 26 Aug 2009 20:18:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9885620</guid><dc:creator>Beth Massi</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9885620.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9885620</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9885620</wfw:comment><description>&lt;p&gt;Yesterday we released a couple more videos onto the &lt;a href="http://msdn.com/vbasic"&gt;Visual Basic Developer Center&lt;/a&gt; on building WPF data-entry forms with Entity Framework:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/vbasic/ee364700.aspx"&gt;How Do I: Hook Up and Display Validation in WPF using Entity Framework?&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/vbasic/ee364701.aspx"&gt;How Do I: Build a WPF Master-Detail Data Entry Form Using Entity Framework?&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;That makes 5 videos total on &lt;a href="http://msdn.microsoft.com/en-us/vbasic/bb466226.aspx#wpfentity"&gt;working with EF in WPF applications&lt;/a&gt;. Others released previously:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/vbasic/dd776537.aspx"&gt;How Do I: Get Started with Entity Framework in WPF Applications?&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/vbasic/dd776540.aspx"&gt;How Do I: Build a WPF Data Entry Form Using Entity Framework?&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/vbasic/dd776544.aspx"&gt;How Do I: Create a WPF Lookup Combobox using Entity Framework?&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;These videos are based on articles I’ve posted here in the past. So if you like reading better that watching videos here you go:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/04/30/data-binding-wpf-lookup-combobox-values-to-ef-entities.aspx"&gt;Data Binding WPF Lookup Combobox Values to EF Entities&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/05/04/notifying-the-ui-when-entity-references-change-in-lookup-comboboxes.aspx"&gt;Notifying the UI when Entity References Change in Lookup Comboboxes&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/05/08/using-the-wpf-observablecollection-with-ef-entities.aspx"&gt;Using the WPF ObservableCollection with EF Entities&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/07/07/implementing-validation-in-wpf-on-entity-framework-entities.aspx"&gt;Implementing Validation in WPF on Entity Framework Entities&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/07/14/master-detail-data-binding-in-wpf-with-entity-framework.aspx"&gt;Master-Detail Data Binding in WPF with Entity Framework&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/07/16/filtering-entity-framework-collections-in-master-detail-forms.aspx"&gt;Filtering Entity Framework Collections in Master-Detail Forms&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;There are also additional resources listed on the How Do I video pages themselves pointing to topics in the MSDN Library.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9885620" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Videos/default.aspx">Videos</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Data/default.aspx">Data</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Entity+Framework/default.aspx">Entity Framework</category></item><item><title>Using Windows Presentation Foundation in Office Clients</title><link>http://blogs.msdn.com/bethmassi/archive/2009/08/10/using-windows-presentation-foundation-in-office-clients.aspx</link><pubDate>Tue, 11 Aug 2009 03:31:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9863656</guid><dc:creator>Beth Massi</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9863656.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9863656</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9863656</wfw:comment><description>&lt;p&gt;&lt;img style="display: inline; margin: 0px 10px 10px 0px" src="http://www.sdn.nl/Portals/0/Upload/Images/2009/Website/VP101.png" align="left" /&gt; I was cleaning up my desk today and in the piles of mail and gobs of paper I found the &lt;a href="http://www.sdn.nl/SDN/Magazine/tabid/66/articleType/ArticleView/articleId/2870/SDN-Magazine-101-Women-In-Technology-is-uit.aspx" target="_blank"&gt;SDN Magazine “Women in Technology” issue 101&lt;/a&gt; that featured an article I wrote that was released in print back in May. Well, I just noticed today that near the end of June they made most of the articles available online, including mine. :-)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.sdn.nl/SDN/Artikelen/tabid/58/agentType/View/PropertyID/2982/Default.aspx"&gt;&lt;strong&gt;Using Windows Presentation Foundation and Line-of-Business Data in Microsoft Office Clients&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In this article I talk about how to expose Line-of-Business data via ADO.NET Data Services to an Excel client using WPF. Office solutions you build with Visual Studio are designed to work with Windows Forms controls but you can also use WPF controls in your solutions as well. Any UI element that can host Windows Forms controls in an Office solution (VSTO) can also host WPF controls using the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.elementhost.aspx" target="_blank"&gt;Winforms ElementHost&lt;/a&gt; as a container. &lt;/p&gt;  &lt;p&gt;Using WPF controls in Office allows you to think out of the box and provide world-class data visualizations that are not possible with Windows Forms controls. And you can do it easily in an instantly familiar end-user application like those in the Office family. But what if you don’t have any fancy data visualizations? Even the simplest controls that display data are often better off as WPF controls in Office applications because they better match the UI styles used in the latest versions of Office. Using WPF can make your add-ins look built into the Office applications themselves, providing a better user experience.&lt;/p&gt;  &lt;p&gt;This article describes one piece of the Northwind Office Business Application (OBA) we created in the beginning of the year so if you’re interested in OBA development with Outlook, Word, Excel and Sharepoint I’d suggest reading these as well:&lt;/p&gt;  &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/03/oba-part-1-exposing-line-of-business-data.aspx"&gt;OBA Part 1 - Exposing Line-of-Business Data&lt;/a&gt;&lt;/li&gt;  &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/07/oba-part-2-building-and-outlook-client-against-lob-data.aspx"&gt;OBA Part 2 - Building and Outlook Client against LOB Data&lt;/a&gt;&lt;/li&gt;  &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/12/oba-part-3-storing-and-reading-data-in-word-documents.aspx"&gt;OBA Part 3 - Storing and Reading Data in Word Documents&lt;/a&gt;&lt;/li&gt;  &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/03/08/oba-part-4-building-an-excel-client-against-lob-data.aspx"&gt;OBA Part 4 - Building an Excel Client against LOB Data&lt;/a&gt;&lt;/li&gt;  &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/04/21/oba-part-5-building-the-sharepoint-2007-workflow.aspx"&gt;OBA Part 5 - Building the SharePoint 2007 Workflow&lt;/a&gt;&lt;/li&gt;  &lt;p&gt;The full sample application, built with Visual Studio 2008, is here: &lt;a title="http://code.msdn.microsoft.com/OBANorthwind" href="http://code.msdn.microsoft.com/OBANorthwind"&gt;http://code.msdn.microsoft.com/OBANorthwind&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Of course, the rest of the magazine is pack full of awesome articles from very well known women in technology (scroll to the bottom of &lt;a href="http://www.sdn.nl/SDN/Magazine/tabid/66/articleType/ArticleView/articleId/2870/SDN-Magazine-101-Women-In-Technology-is-uit.aspx" target="_blank"&gt;this page&lt;/a&gt; for the whole list). I’m honored to be featured with them in this issue. Thanks again to &lt;a href="http://information-worker.org/aboutus.aspx" target="_blank"&gt;Marianne van Wanrooij&lt;/a&gt; and the folks at &lt;a href="http://www.sdn.nl" target="_blank"&gt;SDN&lt;/a&gt; for putting this together and I’ll see you &lt;a href="http://www.sdc.nl/" target="_blank"&gt;in October at the SDN Conference&lt;/a&gt;!&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9863656" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Article/default.aspx">Article</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/XML/default.aspx">XML</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Office/default.aspx">Office</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/ADO.NET+Data+Services/default.aspx">ADO.NET Data Services</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VSTO/default.aspx">VSTO</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/OBA/default.aspx">OBA</category></item><item><title>WPF or Silverlight? Billy Hollis Shares His Thoughts on Channel 9</title><link>http://blogs.msdn.com/bethmassi/archive/2009/07/23/wpf-or-silverlight-billy-hollis-shares-his-thoughts-on-channel-9.aspx</link><pubDate>Thu, 23 Jul 2009 23:25:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9846744</guid><dc:creator>Beth Massi</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9846744.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9846744</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9846744</wfw:comment><description>&lt;P&gt;One of my favorite Visual Basic MVP’s, Billy Hollis, was caught at TechEd by the Patterns&amp;amp;Practices folks for a quick chat. In this short 2-minute interview Billy shares his opinions on WPF and Silverlight. Check it out:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://channel9.msdn.com/posts/KeithPleas/Billy-Hollis-on-WPF-and-Silverlight/" mce_href="http://channel9.msdn.com/posts/KeithPleas/Billy-Hollis-on-WPF-and-Silverlight/"&gt;&lt;STRONG&gt;Billy Hollis on WPF and Silverlight&lt;/STRONG&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;By the way, anyone notice &lt;A href="http://channel9.msdn.com/forums/Coffeehouse/451972-Blue/" target=_blank mce_href="http://channel9.msdn.com/forums/Coffeehouse/451972-Blue/"&gt;Channel 9 turned blue today in honor of Windows 7…&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9846744" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Community/default.aspx">Community</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Channel9/default.aspx">Channel9</category></item><item><title>Filtering Entity Framework Collections in Master-Detail Forms</title><link>http://blogs.msdn.com/bethmassi/archive/2009/07/16/filtering-entity-framework-collections-in-master-detail-forms.aspx</link><pubDate>Fri, 17 Jul 2009 03:18:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9836309</guid><dc:creator>Beth Massi</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9836309.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9836309</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9836309</wfw:comment><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/07/14/master-detail-data-binding-in-wpf-with-entity-framework.aspx" target="_blank"&gt;Last post&lt;/a&gt; I talked about how to get WPF data binding to work with master-detail entity collections. I had a couple readers ask me how they could filter the child collection instead of bringing them all down so in this post I’d like to show how you could do that. It’s actually pretty easy.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Customer (Master) –&amp;lt; Orders (Detail) &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;I created a very simple Entity Data Model (EDM) that demonstrates a Master-Detail relationship. The Orders table is defined in the database with a non-nullable foreign key CustomerID, meaning that no Order can exist without a Customer. This relationship is inferred by Entity Framework (EF) to set up the navigation properties giving us an Orders EntityCollection on Customer. &lt;/p&gt;  &lt;p&gt;&lt;img src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/DataBindingWPFLookupComboboxValuestoEFEn_F345/image_6.png" /&gt;&lt;/p&gt;  &lt;p&gt;To recap, I’ve created my own ObservableCollection(of Customer) called CustomerCollection so that when the UI modifies the collection through AddItem/RemoveItem, we can instruct the ObjectContext to track these changes so that it will insert and delete entities to the database when we call SaveChanges. &lt;/p&gt;  &lt;p&gt;The constructor takes an IEnumerable(Of Customer) which allows us to pass a LINQ to Entities query into our CustomerCollection. This executes the query against the database when we call the base class’s constructor which iterates over the query results and adds the Customer entities to our collection. &lt;/p&gt;  &lt;p&gt;Take a look &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/07/14/master-detail-data-binding-in-wpf-with-entity-framework.aspx" target="_blank"&gt;at the first chunk of code in the last post&lt;/a&gt; for the full code listing for the CustomerCollection class. I don’t have to make any changes to it to support filtering the children. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Loading All Detail Entities &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;If you want to bring down all the Orders for the selected Customer you can use the .Include extension like I’ve shown before using explicit loading. &lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: green"&gt;'EF ObjectContext connects to database and tracks changes
&lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;db &lt;span style="color: blue"&gt;As New &lt;/span&gt;OMSEntities
&lt;span style="color: green"&gt;'inherits from ObservableCollection(Of Customer)
&lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;CustomerData &lt;span style="color: blue"&gt;As &lt;/span&gt;CustomerCollection

&lt;span style="color: green"&gt;'Include all Orders for Customer #1
&lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;customers = &lt;span style="color: blue"&gt;From &lt;/span&gt;c &lt;span style="color: blue"&gt;In &lt;/span&gt;db.Customers.Include(&lt;span style="color: #a31515"&gt;&amp;quot;Orders&amp;quot;&lt;/span&gt;) _
                &lt;span style="color: blue"&gt;Where &lt;/span&gt;c.CustomerID = 1

CustomerData = &lt;span style="color: blue"&gt;New &lt;/span&gt;CustomerCollection(customers, db)&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;This ends up shooting one query to SQL Server to return all the Orders for the selected Customer when we pass the query into our collection. But what if we also wanted to filter the Orders? There’s a couple ways we can do this because of a cool feature of the Entity Framework. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Filtering Detail Entities with a Sub-Query&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When the entities are being created in memory on the client from the query (materialized), the object state manager will attempt to hook up the entity references and collections automatically. This means that all we have to do is specify a filtered query and make sure we execute it by enumerating over the results (or calling ToList). &lt;/p&gt;

&lt;p&gt;So say we wanted to only grab the most recent Orders where the order was placed on or after January 1st, 2009:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;query = &lt;span style="color: blue"&gt;From &lt;/span&gt;c &lt;span style="color: blue"&gt;In &lt;/span&gt;db.Customers _
            &lt;span style="color: blue"&gt;Where &lt;/span&gt;c.CustomerID = 1 _
            &lt;span style="color: blue"&gt;Select &lt;/span&gt;Customer = c, _
&lt;strong&gt;                   Orders = &lt;span style="color: blue"&gt;From &lt;/span&gt;o &lt;span style="color: blue"&gt;In &lt;/span&gt;c.Orders _
                            &lt;span style="color: blue"&gt;Where &lt;/span&gt;o.OrderDate &amp;gt;= #1/1/2009#
&lt;/strong&gt;
&lt;span style="color: blue"&gt;Dim &lt;/span&gt;customers = &lt;span style="color: blue"&gt;From &lt;/span&gt;item &lt;span style="color: blue"&gt;In &lt;/span&gt;&lt;strong&gt;query.ToList&lt;/strong&gt; &lt;span style="color: blue"&gt;Select &lt;/span&gt;item.Customer

CustomerData = &lt;span style="color: blue"&gt;New &lt;/span&gt;CustomerCollection(customers, db)&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Here I’m specifying a sub-query to only pull the Orders I want on the selected Customer. The first query creates a collection of anonymous types that have a Customer object and a filtered Orders collection. In the following query, I need to call query.ToList in order to execute the query against the database and materialize the objects. This sends one statement to SQL Server like before, but this time it’s filtered on Orders as well.&lt;/p&gt;

&lt;p&gt;At this point the Customers and Orders are in memory and the object state manager has hooked them up for us. Meaning that the Customer now has an Orders collection like we want. As long as we Select the entire Customer and Order types in our queries this will work (as opposed to just selecting specific fields – the entity types have to match up for it to work). The second query is just a LINQ to Objects query (in memory) that we’re using so that we can pass an IEnumerable(Of Customer) to our ObservableCollection. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Filtering Detail Entities with &lt;/strong&gt;&lt;strong&gt;Separate Queries&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are other ways we could write this. We could write the queries separately:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;customers = (&lt;span style="color: blue"&gt;From &lt;/span&gt;c &lt;span style="color: blue"&gt;In &lt;/span&gt;db.Customers _
                 &lt;span style="color: blue"&gt;Where &lt;/span&gt;c.CustomerID = 1).ToList()

&lt;span style="color: blue"&gt;Dim &lt;/span&gt;orders = (&lt;span style="color: blue"&gt;From &lt;/span&gt;o &lt;span style="color: blue"&gt;In &lt;/span&gt;db.Orders _
              &lt;span style="color: blue"&gt;Where &lt;/span&gt;o.Customer.CustomerID = 1 &lt;span style="color: blue"&gt;AndAlso &lt;/span&gt;_
                    o.OrderDate &amp;gt; #1/1/2009#).ToList()

CustomerData = &lt;span style="color: blue"&gt;New &lt;/span&gt;CustomerCollection(customers, db)&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Notice that I’m calling ToList to force the queries to execute so that the objects will materialize (come into memory), then I’m just passing the Customers to the constructor because at this point the object state manager has hooked up our entities (Customer has an EntityCollection of Orders based on the filtered query). The results on the client are the same but the major difference here is that &lt;strong&gt;two &lt;/strong&gt;statements are sent to SQL Server, so keep that in mind. I like the first approach better with a sub-query because of the single SQL statement that’s generated as well as the clearer looking LINQ query.&lt;/p&gt;

&lt;p&gt;I’ve updated &lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=wpfdatavideos&amp;amp;DownloadId=6509" target="_blank"&gt;this &lt;strong&gt;sample application&lt;/strong&gt;&lt;/a&gt; that also shows a variety of other data binding techniques with EF and WPF so have a look. The filter example above is in the SimpleMasterDetailBinding form.&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9836309" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Article/default.aspx">Article</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Entity+Framework/default.aspx">Entity Framework</category></item><item><title>Master-Detail Data Binding in WPF with Entity Framework</title><link>http://blogs.msdn.com/bethmassi/archive/2009/07/14/master-detail-data-binding-in-wpf-with-entity-framework.aspx</link><pubDate>Wed, 15 Jul 2009 02:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9833642</guid><dc:creator>Beth Massi</dc:creator><slash:comments>16</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9833642.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9833642</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9833642</wfw:comment><description>&lt;P&gt;Today I thought I would talk about a really common scenario in data applications, creating a master-details (one-to-many) data entry form. I’ve written about WPF data binding and Entity Framework a lot in the past:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Posts:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/bethmassi/archive/2008/12/10/master-details-with-entity-framework-explicit-load.aspx" mce_href="http://blogs.msdn.com/bethmassi/archive/2008/12/10/master-details-with-entity-framework-explicit-load.aspx"&gt;Master-Details with Entity Framework Explicit Load&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/bethmassi/archive/2008/11/07/loading-data-and-binding-controls-in-wpf-with-collectionviewsource.aspx" mce_href="http://blogs.msdn.com/bethmassi/archive/2008/11/07/loading-data-and-binding-controls-in-wpf-with-collectionviewsource.aspx"&gt;Loading Data and Binding Controls in WPF with CollectionViewSource&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/05/08/using-the-wpf-observablecollection-with-ef-entities.aspx" mce_href="http://blogs.msdn.com/bethmassi/archive/2009/05/08/using-the-wpf-observablecollection-with-ef-entities.aspx"&gt;Using the WPF ObservableCollection with EF Entities&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/04/30/data-binding-wpf-lookup-combobox-values-to-ef-entities.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2009/04/30/data-binding-wpf-lookup-combobox-values-to-ef-entities.aspx"&gt;Data Binding WPF Lookup Combobox Values to EF Entities&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/05/04/notifying-the-ui-when-entity-references-change-in-lookup-comboboxes.aspx" mce_href="http://blogs.msdn.com/bethmassi/archive/2009/05/04/notifying-the-ui-when-entity-references-change-in-lookup-comboboxes.aspx"&gt;Notifying the UI when Entity References Change in Lookup Comboboxes&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/07/07/implementing-validation-in-wpf-on-entity-framework-entities.aspx" mce_href="http://blogs.msdn.com/bethmassi/archive/2009/07/07/implementing-validation-in-wpf-on-entity-framework-entities.aspx"&gt;Implementing Validation in WPF on Entity Framework Entities&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;Videos:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/vbasic/dd776537.aspx" mce_href="http://msdn.microsoft.com/en-us/vbasic/dd776537.aspx"&gt;How Do I: Get Started with Entity Framework in WPF Applications?&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/vbasic/dd776540.aspx" mce_href="http://msdn.microsoft.com/en-us/vbasic/dd776540.aspx"&gt;How Do I: Build a WPF Data Entry Form Using Entity Framework?&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/vbasic/dd776544.aspx" mce_href="http://msdn.microsoft.com/en-us/vbasic/dd776544.aspx"&gt;How Do I: Create a WPF Lookup Combobox using Entity Framework?&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/vbasic/dd239277.aspx" mce_href="http://msdn.microsoft.com/en-us/vbasic/dd239277.aspx"&gt;How Do I: Create a Master-Detail Data Entry Form in WPF?&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Today I want to pull these concepts together and walk through one way to create a master-detail form in WPF using entities from the Entity Framework. Specifically, we’ll declare CollectionViewSources in our XAML &lt;A href="http://blogs.msdn.com/bethmassi/archive/2008/11/07/loading-data-and-binding-controls-in-wpf-with-collectionviewsource.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2008/11/07/loading-data-and-binding-controls-in-wpf-with-collectionviewsource.aspx"&gt;like I showed here&lt;/A&gt;, to bind to an ObservableCollection of entities &lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/05/08/using-the-wpf-observablecollection-with-ef-entities.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2009/05/08/using-the-wpf-observablecollection-with-ef-entities.aspx"&gt;like I showed here&lt;/A&gt;, where the children are explicitly loaded &lt;A href="http://blogs.msdn.com/bethmassi/archive/2008/12/10/master-details-with-entity-framework-explicit-load.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2008/12/10/master-details-with-entity-framework-explicit-load.aspx"&gt;like I showed here&lt;/A&gt;. Everybody got that? ;-)&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Creating the Entity Data Model&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;First let’s create a simple Entity Data Model (EDM) that demonstrates a Master-Detail relationship. I’ll use a simple database called OMS that has Customer and Orders tables with a non-nullable foreign key set up between them on CustomerID, meaning that no Order can exist without a Customer. This relationship is inferred by Entity Framework (EF) to set up the navigation properties. Notice that there is an Orders EntityCollection on Customer. &lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/DataBindingWPFLookupComboboxValuestoEFEn_F345/image_6.png" mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/DataBindingWPFLookupComboboxValuestoEFEn_F345/image_6.png"&gt; &lt;/P&gt;
&lt;P&gt;What we want to do is build a simple form that will let us Edit, Add, and Delete Customers and their Orders. First let’s set up the WPF Data Binding in XAML. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Defining the CollectionViewSource and Data Bindings &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;To recap, a CollectionViewSource is a proxy for the CollectionView which manages the currency (the position) in the list of entities. It has a property called &lt;EM&gt;Source&lt;/EM&gt; which can be set in our code behind. This way, we can set up CollectionVieSources in XAML for all our data lists and bind them to the corresponding controls all in XAML. Then at runtime in our code we set the Source properties and only at that time does the data pull from the database. &lt;/P&gt;
&lt;P&gt;To define a Master-Detail relationship we define two CollectionViewSources one for the master and one for the detail collections. Then on the detail we set the Source property to the master CollectionViewSource and then specify the Path property as the name of the child collection. In our case the name of the collection on Customer is “Orders”. So we can specify the XAML like so:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Window.Resources&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;CollectionViewSource &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="MasterViewSource" /&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;CollectionViewSource &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="DetailsViewSource" 
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Source&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Source&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;={&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;MasterViewSource&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}, &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;='Orders'}" /&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Window.Resources&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;Now as the position changes in the MasterViewSource to point to a new Customer, the DetailsViewSource will filter automatically to only those related Orders for that Customer. We can now set the rest of the data bindings on the controls on the form by setting the BindingContext of the container controls to the CollectionViewSource we want to display. For example, we can set up a StackPanel to contain the Customer fields and set the StackPanel.DataContext to the MasterViewSource. Under that we can set up a ListView to display the Orders by setting the ListView.ItemsSource to the DetailsViewSource.&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;...&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StackPanel &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="StackPanel2" &lt;BR&gt;                &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Grid.Column&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="1" &lt;BR&gt;                &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: red"&gt;DataContext&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Source&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;={&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;MasterViewSource&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;}"&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="TextBox1" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;IsReadOnly&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="True" 
                 &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=CustomerID, &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Mode&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=OneWay}"/&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="TextBox5"&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;                 Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=LastName}"/&amp;gt;&lt;BR&gt;...
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
...&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Grid.Row&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="3" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="ListView1" 
              &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;IsSynchronizedWithCurrentItem&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="True"
&lt;STRONG&gt;              &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: red"&gt;ItemsSource&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Source&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;={&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;DetailsViewSource&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;STRONG&gt;}}"&amp;gt;
&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.View&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
                &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Header&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="ID" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="75"&amp;gt;
                    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn.CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
                        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
                        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Label &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Content&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=OrderID}" 
                                     &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="-6,0,-6,0"/&amp;gt;
                        &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
                    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn.CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
                &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
                &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Header&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Order Date" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="100"&amp;gt;
                    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn.CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
                        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
                            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=OrderDate}" 
                                     &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="-6,0,-6,0"/&amp;gt;
                        &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
                    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn.CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
                &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
...&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;The only thing we need to do now is set the Source property of the MasterViewSource in code to the collection of our Customer entities. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Defining the Master-Detail Entities in an ObservableCollection&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;I showed before how we can create a collection of entities that inherits from ObservableCollection &lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/05/08/using-the-wpf-observablecollection-with-ef-entities.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2009/05/08/using-the-wpf-observablecollection-with-ef-entities.aspx"&gt;in this post&lt;/A&gt; to make it easier to work with WPF data binding. But in that example we were only working with a simple collection of Customers and not their Orders. If you recall, the ObjectContext is what tracks changes on entities so in order for the ObjectContext to be notified that adds and deletes to the ObservableCollection need to be tracked you need to override the InsertItem and RemoveItem methods so that you can tell the ObjectContext to either add or delete the entity which will ultimately execute against the database. In the constructor I pass a reference to the ObjectContext. You can also pass in any collection of entities, say from a LINQ query, and then add them to the ObservableCollection. However, we need to make a couple modifications to our collection so that we can also track the child order entities correctly. &lt;/P&gt;
&lt;P&gt;Adds to the Customer.Orders EntityCollection will will cause the addition of a new Order to the collection as well as the association to Customer automatically. However removing the Order from the Customer.Orders EntityCollection will only &lt;EM&gt;remove the association &lt;/EM&gt;and will not attempt to actually delete the Order from the database. Instead it attempts to set the CustomerID to NULL (to remove the association from the Customer) but since we have referential integrity set up to disallow this we will get an error if we attempt to SaveChanges. &lt;/P&gt;
&lt;P&gt;In a lot of scenarios it makes sense to just remove the association and set the foreign key to NULL in the database. But in this example we really mean to delete the Order record completely when the Order is removed from the collection. So the key is adding an event handler to the AssociationChanged event on the Orders EntityCollection that’s hanging off our Customer entity and telling the ObjectContext to explicitly delete the Order. &lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Public Class &lt;/SPAN&gt;CustomerCollection
    &lt;SPAN style="COLOR: blue"&gt;Inherits &lt;/SPAN&gt;ObservableCollection(&lt;SPAN style="COLOR: blue"&gt;Of &lt;/SPAN&gt;Customer)

    &lt;SPAN style="COLOR: blue"&gt;Private &lt;/SPAN&gt;_context &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;OMSEntities
    &lt;SPAN style="COLOR: blue"&gt;Public ReadOnly Property &lt;/SPAN&gt;Context() &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;OMSEntities
        &lt;SPAN style="COLOR: blue"&gt;Get
            Return &lt;/SPAN&gt;_context
        &lt;SPAN style="COLOR: blue"&gt;End Get
    End Property


    Sub New&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;customers &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;IEnumerable(&lt;SPAN style="COLOR: blue"&gt;Of &lt;/SPAN&gt;Customer), &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;context &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;OMSEntities)
        &lt;SPAN style="COLOR: blue"&gt;MyBase&lt;/SPAN&gt;.New(customers)
        _context = context

        &lt;SPAN style="COLOR: blue"&gt;For Each &lt;/SPAN&gt;c &lt;SPAN style="COLOR: blue"&gt;In &lt;/SPAN&gt;customers
            &lt;SPAN style="COLOR: blue"&gt;AddHandler &lt;/SPAN&gt;c.Orders.AssociationChanged, &lt;SPAN style="COLOR: blue"&gt;AddressOf &lt;/SPAN&gt;Orders_CollectionChanged
        &lt;SPAN style="COLOR: blue"&gt;Next
    End Sub

    Protected Overrides Sub &lt;/SPAN&gt;InsertItem(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;index &lt;SPAN style="COLOR: blue"&gt;As Integer&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;item &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Customer)
        &lt;SPAN style="COLOR: blue"&gt;AddHandler &lt;/SPAN&gt;item.Orders.AssociationChanged, &lt;SPAN style="COLOR: blue"&gt;AddressOf &lt;/SPAN&gt;Orders_CollectionChanged

        &lt;SPAN style="COLOR: green"&gt;'Tell the ObjectContext to start tracking this customer entity
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.Context.AddToCustomers(item)
        &lt;SPAN style="COLOR: blue"&gt;MyBase&lt;/SPAN&gt;.InsertItem(index, item)
    &lt;SPAN style="COLOR: blue"&gt;End Sub

    Protected Overrides Sub &lt;/SPAN&gt;RemoveItem(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;index &lt;SPAN style="COLOR: blue"&gt;As Integer&lt;/SPAN&gt;)
        &lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;customer = &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;(index)
        &lt;SPAN style="COLOR: blue"&gt;RemoveHandler &lt;/SPAN&gt;customer.Orders.AssociationChanged, &lt;SPAN style="COLOR: blue"&gt;AddressOf &lt;/SPAN&gt;Orders_CollectionChanged

        &lt;SPAN style="COLOR: blue"&gt;For &lt;/SPAN&gt;i = customer.Orders.Count - 1 &lt;SPAN style="COLOR: blue"&gt;To &lt;/SPAN&gt;0 &lt;SPAN style="COLOR: blue"&gt;Step &lt;/SPAN&gt;-1
            &lt;SPAN style="COLOR: green"&gt;'When deleting a customer, delete any orders if any exist
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.Context.DeleteObject(customer.Orders(i))
        &lt;SPAN style="COLOR: blue"&gt;Next

        &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;'Tell the ObjectContext to delete this customer entity
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.Context.DeleteObject(customer)
        &lt;SPAN style="COLOR: blue"&gt;MyBase&lt;/SPAN&gt;.RemoveItem(index)
    &lt;SPAN style="COLOR: blue"&gt;End Sub

    Private Sub &lt;/SPAN&gt;Orders_CollectionChanged(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;sender &lt;SPAN style="COLOR: blue"&gt;As Object&lt;/SPAN&gt;, _
                                         &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;e &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;CollectionChangeEventArgs)
        &lt;SPAN style="COLOR: blue"&gt;If &lt;/SPAN&gt;e.Action = CollectionChangeAction.Remove &lt;SPAN style="COLOR: blue"&gt;Then
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;'Adding an order to a customer is handled automatically 
            ' for us but we need to tell the ObjectContext to delete the order
            ' if an order is removed from the Orders EntityCollection 
           &lt;STRONG&gt; &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.Context.DeleteObject(&lt;SPAN style="COLOR: blue"&gt;CType&lt;/SPAN&gt;(e.Element, Order))&lt;/STRONG&gt;
        &lt;SPAN style="COLOR: blue"&gt;End If
    End Sub
End Class
&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;&lt;STRONG&gt;Loading the Master-Detail Entities &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Finally we’re ready to write a LINQ query to load the entities into our CustomerCollection and then set that as the Source property of the MasterViewSource. In this example I’m loading the Orders explicitly by calling .Include(“Orders”) on the LINQ query which constructs a single statement to retrieve the Customer and all their Orders from the database. &lt;A href="http://blogs.msdn.com/bethmassi/archive/2008/12/10/master-details-with-entity-framework-explicit-load.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2008/12/10/master-details-with-entity-framework-explicit-load.aspx"&gt;I discuss explicit load in this post&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;We can then grab a reference to the MasterViewSource &amp;amp; DetailViewSource’s View property in order to add/remove items in the collections. When we’re done, we can call SaveChanges on the ObjectContext and the database will be updated. &lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Private &lt;/SPAN&gt;db &lt;SPAN style="COLOR: blue"&gt;As New &lt;/SPAN&gt;OMSEntities &lt;SPAN style="COLOR: green"&gt;'EF ObjectContext connects to database and tracks changes
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Private &lt;/SPAN&gt;CustomerData &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;CustomerCollection &lt;SPAN style="COLOR: green"&gt;'inherits from ObservableCollection

&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Private &lt;/SPAN&gt;MasterViewSource &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;CollectionViewSource
&lt;SPAN style="COLOR: blue"&gt;Private &lt;/SPAN&gt;DetailViewSource &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;CollectionViewSource

&lt;SPAN style="COLOR: green"&gt;'provides currency to controls (position &amp;amp; movement in the collections)
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Private WithEvents &lt;/SPAN&gt;MasterView &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;ListCollectionView
&lt;SPAN style="COLOR: blue"&gt;Private &lt;/SPAN&gt;DetailsView &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;BindingListCollectionView

&lt;SPAN style="COLOR: blue"&gt;Private Sub &lt;/SPAN&gt;Window_Loaded() &lt;SPAN style="COLOR: blue"&gt;Handles MyBase&lt;/SPAN&gt;.Loaded

    &lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;query = &lt;SPAN style="COLOR: blue"&gt;From &lt;/SPAN&gt;c &lt;SPAN style="COLOR: blue"&gt;In &lt;/SPAN&gt;db.Customers.Include(&lt;SPAN style="COLOR: #a31515"&gt;"Orders"&lt;/SPAN&gt;) _
                &lt;SPAN style="COLOR: blue"&gt;Where &lt;/SPAN&gt;c.CustomerID = 1 _
                &lt;SPAN style="COLOR: blue"&gt;Select &lt;/SPAN&gt;c

    &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.CustomerData = &lt;SPAN style="COLOR: blue"&gt;New &lt;/SPAN&gt;CustomerCollection(query, db)

    &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.MasterViewSource = &lt;SPAN style="COLOR: blue"&gt;CType&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.FindResource(&lt;SPAN style="COLOR: #a31515"&gt;"MasterViewSource"&lt;/SPAN&gt;), CollectionViewSource)
    &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.DetailViewSource = &lt;SPAN style="COLOR: blue"&gt;CType&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.FindResource(&lt;SPAN style="COLOR: #a31515"&gt;"DetailsViewSource"&lt;/SPAN&gt;), CollectionViewSource)
    &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.MasterViewSource.Source = &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.CustomerData

    &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.MasterView = &lt;SPAN style="COLOR: blue"&gt;CType&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.MasterViewSource.View, ListCollectionView)
    &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.DetailsView = &lt;SPAN style="COLOR: blue"&gt;CType&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.DetailViewSource.View, BindingListCollectionView)
&lt;SPAN style="COLOR: blue"&gt;End Sub&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Private Sub &lt;/SPAN&gt;MasterView_CurrentChanged() &lt;SPAN style="COLOR: blue"&gt;Handles &lt;/SPAN&gt;MasterView.CurrentChanged
    &lt;SPAN style="COLOR: green"&gt;'We need to grab the new child view when the master's position changes
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.DetailsView = &lt;SPAN style="COLOR: blue"&gt;CType&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.DetailViewSource.View, BindingListCollectionView)
&lt;SPAN style="COLOR: blue"&gt;End Sub

Private Sub &lt;/SPAN&gt;btnSave_Click() &lt;SPAN style="COLOR: blue"&gt;Handles &lt;/SPAN&gt;btnSave.Click
    &lt;SPAN style="COLOR: blue"&gt;Try
        &lt;/SPAN&gt;db.SaveChanges()
        MessageBox.Show(&lt;SPAN style="COLOR: #a31515"&gt;"Customer data saved."&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.Title, MessageBoxButton.OK, MessageBoxImage.Information)
    &lt;SPAN style="COLOR: blue"&gt;Catch &lt;/SPAN&gt;ex &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Exception
        MsgBox(ex.ToString())
    &lt;SPAN style="COLOR: blue"&gt;End Try
End Sub

Private Sub &lt;/SPAN&gt;btnDelete_Click() &lt;SPAN style="COLOR: blue"&gt;Handles &lt;/SPAN&gt;btnDelete.Click
    &lt;SPAN style="COLOR: blue"&gt;If Me&lt;/SPAN&gt;.MasterView.CurrentPosition &amp;gt; -1 &lt;SPAN style="COLOR: blue"&gt;Then
        Me&lt;/SPAN&gt;.MasterView.RemoveAt(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.MasterView.CurrentPosition)
    &lt;SPAN style="COLOR: blue"&gt;End If
End Sub

Private Sub &lt;/SPAN&gt;btnAdd_Click() &lt;SPAN style="COLOR: blue"&gt;Handles &lt;/SPAN&gt;btnAdd.Click
    &lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;customer = &lt;SPAN style="COLOR: blue"&gt;CType&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.MasterView.AddNew, Customer)
    &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.MasterView.CommitNew()
&lt;SPAN style="COLOR: blue"&gt;End Sub

Private Sub &lt;/SPAN&gt;btnPrevious_Click() &lt;SPAN style="COLOR: blue"&gt;Handles &lt;/SPAN&gt;btnPrevious.Click
    &lt;SPAN style="COLOR: blue"&gt;If Me&lt;/SPAN&gt;.MasterView.CurrentPosition &amp;gt; 0 &lt;SPAN style="COLOR: blue"&gt;Then
        Me&lt;/SPAN&gt;.MasterView.MoveCurrentToPrevious()
    &lt;SPAN style="COLOR: blue"&gt;End If
End Sub

Private Sub &lt;/SPAN&gt;btnNext_Click() &lt;SPAN style="COLOR: blue"&gt;Handles &lt;/SPAN&gt;btnNext.Click
    &lt;SPAN style="COLOR: blue"&gt;If Me&lt;/SPAN&gt;.MasterView.CurrentPosition &amp;lt; &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.MasterView.Count - 1 &lt;SPAN style="COLOR: blue"&gt;Then
        Me&lt;/SPAN&gt;.MasterView.MoveCurrentToNext()
    &lt;SPAN style="COLOR: blue"&gt;End If
End Sub

Private Sub &lt;/SPAN&gt;btnAddDetail_Click() &lt;SPAN style="COLOR: blue"&gt;Handles &lt;/SPAN&gt;btnAddDetail.Click
    &lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;order = &lt;SPAN style="COLOR: blue"&gt;CType&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.DetailsView.AddNew, Order)
    &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.DetailsView.CommitNew()
&lt;SPAN style="COLOR: blue"&gt;End Sub

Private Sub &lt;/SPAN&gt;btnDeleteDetail_Click() &lt;SPAN style="COLOR: blue"&gt;Handles &lt;/SPAN&gt;btnDeleteDetail.Click
    &lt;SPAN style="COLOR: blue"&gt;If Me&lt;/SPAN&gt;.DetailsView.CurrentPosition &amp;gt; -1 &lt;SPAN style="COLOR: blue"&gt;Then
        Me&lt;/SPAN&gt;.DetailsView.RemoveAt(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.DetailsView.CurrentPosition)
    &lt;SPAN style="COLOR: blue"&gt;End If
End Sub&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Now we can Add, Edit, and Delete Customer and their Orders at the same time and changes will be propagated properly to the database through Entity Framework in one call to SaveChanges. I’ve updated &lt;A href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=wpfdatavideos&amp;amp;DownloadId=6509" target=_blank mce_href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=wpfdatavideos&amp;amp;DownloadId=6509"&gt;this complete &lt;STRONG&gt;sample application&lt;/STRONG&gt;&lt;/A&gt; that demonstrates this as well as other aspects of WPF Data Binding with Entity Framework so have a look.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;UPDATE&lt;/STRONG&gt;: Milind talks about some of the tooling improvements in Visual Studio 2010 on the VSData blog regarding building WPF forms against Entity Data Models so check it out --&amp;gt;&amp;nbsp;&lt;A href="http://blogs.msdn.com/vsdata/archive/2009/05/20/wpf-data-binding-creating-a-master-details-form-in-visual-studio-2010.aspx"&gt;WPF Data Binding: Creating a Master-Details form in Visual Studio 2010&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9833642" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Article/default.aspx">Article</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Data/default.aspx">Data</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Entity+Framework/default.aspx">Entity Framework</category></item><item><title>Implementing Validation in WPF on Entity Framework Entities</title><link>http://blogs.msdn.com/bethmassi/archive/2009/07/07/implementing-validation-in-wpf-on-entity-framework-entities.aspx</link><pubDate>Wed, 08 Jul 2009 03:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9823270</guid><dc:creator>Beth Massi</dc:creator><slash:comments>13</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9823270.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9823270</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9823270</wfw:comment><description>&lt;P&gt;I’ve blogged before about implementing &lt;A href="http://blogs.msdn.com/bethmassi/archive/2008/02/25/simple-validation-with-linq-to-sql-classes.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2008/02/25/simple-validation-with-linq-to-sql-classes.aspx"&gt;validation on LINQ to SQL classes&lt;/A&gt; as well as how to &lt;A href="http://blogs.msdn.com/bethmassi/archive/2008/06/27/displaying-data-validation-messages-in-wpf.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2008/06/27/displaying-data-validation-messages-in-wpf.aspx"&gt;customize the display of error messages in WPF&lt;/A&gt;. In this post I want to show how you can use these same techniques to validate entities coming from the Entity Framework (EF). Like LINQ to SQL classes, Entity Framework entities are implemented as &lt;A href="http://msdn.microsoft.com/en-us/library/yfzd5350.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/yfzd5350.aspx"&gt;partial classes&lt;/A&gt; so that you can extend them with your own code on top of the code that the designers generate for you. You can extend EF entities in a similar way as LINQ to SQL classes.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Creating the Partial Class&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Let’s take the example that I started &lt;A href="http://msdn.microsoft.com/en-us/dd776540.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/dd776540.aspx"&gt;here in this How Do I video&lt;/A&gt; on building a simple data entry form to edit customers. You can &lt;A href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=wpfdatavideos&amp;amp;DownloadId=6316" target=_blank mce_href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=wpfdatavideos&amp;amp;DownloadId=6316"&gt;download the code for that video here&lt;/A&gt;. In this sample I have two projects, one for the WPF client (WpfEfDataEntry) and one for the Data Access Layer (WpfEfDAL) that contains a simple Entity Data Model (edmx) of a little database I created that tracks customers and their orders. &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/ImplementingValidationinWPFonEFEntities_A82B/image_2.png" mce_href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/ImplementingValidationinWPFonEFEntities_A82B/image_2.png"&gt;&lt;IMG title=image style="BORDER-TOP-WIDTH: 0px; DISPLAY: inline; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; MARGIN: 0px; BORDER-RIGHT-WIDTH: 0px" height=320 alt=image src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/ImplementingValidationinWPFonEFEntities_A82B/image_thumb.png" width=242 align=left border=0 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/ImplementingValidationinWPFonEFEntities_A82B/image_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/ImplementingValidationinWPFonEFEntities_A82B/image_10.png" mce_href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/ImplementingValidationinWPFonEFEntities_A82B/image_10.png"&gt;&lt;IMG title=image style="BORDER-TOP-WIDTH: 0px; DISPLAY: inline; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=416 alt=image src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/ImplementingValidationinWPFonEFEntities_A82B/image_thumb_4.png" width=473 border=0 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/ImplementingValidationinWPFonEFEntities_A82B/image_thumb_4.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;To extend the Customer class that is generated from the EF designer, right-click on the DAL project and select Add –&amp;gt; Class then name it Customer. This places the class in the same Namespace as the entities that are generated by the designer. This is necessary for partial classes to work. (Partial classes are just a way that you can define one class in multiple physical files and Visual Studio will handle compiling them into one class for you.) &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/ImplementingValidationinWPFonEFEntities_A82B/image_12.png" mce_href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/ImplementingValidationinWPFonEFEntities_A82B/image_12.png"&gt;&lt;IMG title=image style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; DISPLAY: inline; MARGIN: 0px 15px 0px 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=352 alt=image src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/ImplementingValidationinWPFonEFEntities_A82B/image_thumb_5.png" width=324 align=left border=0 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/ImplementingValidationinWPFonEFEntities_A82B/image_thumb_5.png"&gt;&lt;/A&gt; Here’s a trick in VB. You know you got your partial class in the right namespace when you drop down the Declarations dropdown and you see the list of partial methods and properties that the class defines. &lt;/P&gt;
&lt;P&gt;Also in VB the Partial keyword is only required on one of the class declarations in one of the files. (In C# it’s required on all of them.) The EF designer generates the Customer class with the partial keyword. If you click the “Show all Files” button on the Solution Explorer toolbar and then expand the .edmx you can open the .Designer file and see the entity Partial Class definitions:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Partial Public Class &lt;/SPAN&gt;Customer    &lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;You can of course be explicit in VB and add the Partial keyword to all your partial class files as well. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Adding Validation to the Partial Class&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;To add validation we can implement the IDataErrorInfo interface in our customer partial class. Using this interface will make validation errors display in Winforms as well as WPF so I tend to prefer this implementation over others like &lt;A href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.validationrules.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.validationrules.aspx"&gt;ValidationRules collection&lt;/A&gt; in WPF. For this example let’s make sure that the LastName field isn’t empty but we’ll also provide a default value by specifying it in the constructor. This code is the same code we would use if we were working with LINQ to SQL classes. &lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Imports &lt;/SPAN&gt;System.ComponentModel

&lt;SPAN style="COLOR: blue"&gt;Partial Public Class &lt;/SPAN&gt;Customer
    &lt;SPAN style="COLOR: blue"&gt;Implements &lt;/SPAN&gt;IDataErrorInfo

&lt;SPAN style="COLOR: blue"&gt;#Region &lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"IDataErrorInfo Members"
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Private &lt;/SPAN&gt;m_validationErrors &lt;SPAN style="COLOR: blue"&gt;As New &lt;/SPAN&gt;Dictionary(&lt;SPAN style="COLOR: blue"&gt;Of String&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;String&lt;/SPAN&gt;)

    &lt;SPAN style="COLOR: blue"&gt;Private Sub &lt;/SPAN&gt;AddError(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;columnName &lt;SPAN style="COLOR: blue"&gt;As String&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;msg &lt;SPAN style="COLOR: blue"&gt;As String&lt;/SPAN&gt;)
        &lt;SPAN style="COLOR: blue"&gt;If Not &lt;/SPAN&gt;m_validationErrors.ContainsKey(columnName) &lt;SPAN style="COLOR: blue"&gt;Then
            &lt;/SPAN&gt;m_validationErrors.Add(columnName, msg)
        &lt;SPAN style="COLOR: blue"&gt;End If
    End Sub

    Private Sub &lt;/SPAN&gt;RemoveError(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;columnName &lt;SPAN style="COLOR: blue"&gt;As String&lt;/SPAN&gt;)
        &lt;SPAN style="COLOR: blue"&gt;If &lt;/SPAN&gt;m_validationErrors.ContainsKey(columnName) &lt;SPAN style="COLOR: blue"&gt;Then
            &lt;/SPAN&gt;m_validationErrors.Remove(columnName)
        &lt;SPAN style="COLOR: blue"&gt;End If
    End Sub

    Public ReadOnly Property &lt;/SPAN&gt;HasErrors() &lt;SPAN style="COLOR: blue"&gt;As Boolean
        Get
            Return &lt;/SPAN&gt;m_validationErrors.Count &amp;gt; 0
        &lt;SPAN style="COLOR: blue"&gt;End Get
    End Property

    Public ReadOnly Property &lt;/SPAN&gt;[Error]() &lt;SPAN style="COLOR: blue"&gt;As String _&lt;BR&gt;        Implements &lt;/SPAN&gt;System.ComponentModel.IDataErrorInfo.Error
        &lt;SPAN style="COLOR: blue"&gt;Get
            If &lt;/SPAN&gt;m_validationErrors.Count &amp;gt; 0 &lt;SPAN style="COLOR: blue"&gt;Then
                Return &lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"Customer data is invalid"
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Else
                Return Nothing
            End If
        End Get
    End Property

    Default Public ReadOnly Property &lt;/SPAN&gt;Item(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;columnName &lt;SPAN style="COLOR: blue"&gt;As String&lt;/SPAN&gt;) &lt;SPAN style="COLOR: blue"&gt;As String _&lt;BR&gt;        Implements &lt;/SPAN&gt;System.ComponentModel.IDataErrorInfo.Item
        &lt;SPAN style="COLOR: blue"&gt;Get
            If &lt;/SPAN&gt;m_validationErrors.ContainsKey(columnName) &lt;SPAN style="COLOR: blue"&gt;Then
                Return &lt;/SPAN&gt;m_validationErrors(columnName).ToString
            &lt;SPAN style="COLOR: blue"&gt;Else
                Return Nothing
            End If
        End Get
    End Property
#End Region

    Public Sub New&lt;/SPAN&gt;()
        &lt;SPAN style="COLOR: green"&gt;'Set defaults
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.LastName = &lt;SPAN style="COLOR: #a31515"&gt;"[new]"
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;End Sub&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now we can write our validation code to check the LastName field. If you look back at the generated Customer class in the .Designer file, notice that there are On&lt;EM&gt;FieldName&lt;/EM&gt;Changing and On&lt;EM&gt;FieldName&lt;/EM&gt;Changed methods that are also declared as Partial. These are &lt;A href="http://msdn.microsoft.com/en-us/library/bb531348.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/bb531348.aspx"&gt;partial methods&lt;/A&gt;, a new feature introduced with Visual Studio 2008, that allow you to supply additional code that is called from the generated class. The Changing/Changed methods are called in the property setters. We’ll define the OnLastNameChanged to make sure the user enters a LastName:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: green"&gt;    ''' &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;''' This method is called in the LastName property setter of the customer
    '''  partial class generated by the Entity Data Model designer.
    ''' &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Private Sub &lt;/SPAN&gt;OnLastNameChanged()
        &lt;SPAN style="COLOR: green"&gt;'Perform validation. 
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;If &lt;/SPAN&gt;_LastName &lt;SPAN style="COLOR: blue"&gt;Is Nothing OrElse &lt;/SPAN&gt;_LastName.Trim() = &lt;SPAN style="COLOR: #a31515"&gt;"" &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;OrElse &lt;/SPAN&gt;_LastName.Trim() = &lt;SPAN style="COLOR: #a31515"&gt;"[new]" &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Then
            Me&lt;/SPAN&gt;.AddError(&lt;SPAN style="COLOR: #a31515"&gt;"LastName"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Please enter a last name."&lt;/SPAN&gt;)
        &lt;SPAN style="COLOR: blue"&gt;Else
            Me&lt;/SPAN&gt;.RemoveError(&lt;SPAN style="COLOR: #a31515"&gt;"LastName"&lt;/SPAN&gt;)
        &lt;SPAN style="COLOR: blue"&gt;End If
    End Sub

End Class
&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Now all we need to do is specify on the binding in the XAML of the WPF form to display the validation errors.&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="txtLastName" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Auto" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="28" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="3" 
         &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=LastName, &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;&lt;STRONG&gt;ValidatesOnDataErrors&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;STRONG&gt;=True&lt;/STRONG&gt;}"/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;This is exactly the same as we did &lt;A href="http://blogs.msdn.com/bethmassi/archive/2008/06/27/displaying-data-validation-messages-in-wpf.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2008/06/27/displaying-data-validation-messages-in-wpf.aspx"&gt;in this post&lt;/A&gt; when working with LINQ to SQL. Read that post to also see how to change the default error template which controls how the errors are displayed.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Adding Validation to Entity References&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;As you can see validating scalar properties on EF entities works the same as with LINQ to SQL classes. However what if we wanted to make sure that an entity reference was also specified on an EF entity? &lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/05/04/notifying-the-ui-when-entity-references-change-in-lookup-comboboxes.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2009/05/04/notifying-the-ui-when-entity-references-change-in-lookup-comboboxes.aspx"&gt;I’ve posted before&lt;/A&gt; about how to get notified when entity references change. But what if we also want to make sure an entity reference is not empty? For instance, in the case of the Order entity above, how would we write a validation to make sure that the Customer entity reference was specified on the Order before we tried to save? &lt;/P&gt;
&lt;P&gt;Looking back up at the Customer (1)—(*) Order in the diagram above, the Order entity has a reference to its Customer parent as specified by the navigation property. In the database there is a foreign key relationship on CustomerID and that is inferred here by EF. This is a difference from LINQ to SQL classes where the classes contain the foreign keys as scalar properties as well. We can’t validate EF entities the same way because there are no scalar properties for the foreign keys. Instead we need to add an event handler to the AssociationChanged event on the entity reference (&lt;A class="" href="http://blogs.msdn.com/bethmassi/archive/2009/05/04/notifying-the-ui-when-entity-references-change-in-lookup-comboboxes.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2009/05/04/notifying-the-ui-when-entity-references-change-in-lookup-comboboxes.aspx"&gt;like I showed before&lt;/A&gt;) and then add in our validation. Remember that the AssociationChanged event will fire twice when we are selecting a new reference, once when the old entity reference is removed and then once when the new one is added. &lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Imports &lt;/SPAN&gt;System.ComponentModel

&lt;SPAN style="COLOR: blue"&gt;Public Class &lt;/SPAN&gt;Order
    &lt;SPAN style="COLOR: blue"&gt;Implements &lt;/SPAN&gt;IDataErrorInfo

    &lt;SPAN style="COLOR: blue"&gt;Public Sub New&lt;/SPAN&gt;()
        &lt;SPAN style="COLOR: green"&gt;'Handle this event so that UI can be notified if the customer is changed
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;AddHandler Me&lt;/SPAN&gt;.CustomerReference.AssociationChanged, &lt;SPAN style="COLOR: blue"&gt;AddressOf &lt;/SPAN&gt;Customer_AssociationChanged

        &lt;SPAN style="COLOR: green"&gt;'Set defaults
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.OrderDate = &lt;SPAN style="COLOR: blue"&gt;Date&lt;/SPAN&gt;.Today()
        &lt;SPAN style="COLOR: green"&gt;'Customer is required &lt;/SPAN&gt;&lt;BR&gt;        &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.AddError(&lt;SPAN style="COLOR: #a31515"&gt;"Customer"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Please select a customer."&lt;/SPAN&gt;)
    &lt;SPAN style="COLOR: blue"&gt;End Sub

    Private Sub &lt;/SPAN&gt;Customer_AssociationChanged(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;sender &lt;SPAN style="COLOR: blue"&gt;As Object&lt;/SPAN&gt;, _
                                            &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;e &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;CollectionChangeEventArgs)
        &lt;SPAN style="COLOR: blue"&gt;If &lt;/SPAN&gt;e.Action = CollectionChangeAction.Remove &lt;SPAN style="COLOR: blue"&gt;Then
            &lt;/SPAN&gt;OnPropertyChanging(&lt;SPAN style="COLOR: #a31515"&gt;"Customer"&lt;/SPAN&gt;)
        &lt;SPAN style="COLOR: blue"&gt;Else
            If &lt;/SPAN&gt;e.Action = CollectionChangeAction.Add &lt;SPAN style="COLOR: blue"&gt;Then
                Me&lt;/SPAN&gt;.RemoveError(&lt;SPAN style="COLOR: #a31515"&gt;"Customer"&lt;/SPAN&gt;)
            &lt;SPAN style="COLOR: blue"&gt;End If
            &lt;/SPAN&gt;OnPropertyChanged(&lt;SPAN style="COLOR: #a31515"&gt;"Customer"&lt;/SPAN&gt;)
        &lt;SPAN style="COLOR: blue"&gt;End If
    End Sub&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/ImplementingValidationinWPFonEFEntities_A82B/image_16.png" mce_href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/ImplementingValidationinWPFonEFEntities_A82B/image_16.png"&gt;&lt;IMG title=image style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; DISPLAY: inline; MARGIN: 0px 15px 0px 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=153 alt=image src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/ImplementingValidationinWPFonEFEntities_A82B/image_thumb_7.png" width=223 align=left border=0 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/ImplementingValidationinWPFonEFEntities_A82B/image_thumb_7.png"&gt;&lt;/A&gt;What I’m doing is putting the Order in an immediate error state so that the user can see that a Customer must be selected on the Order before it is valid. The error will only go away once they select a Customer.&lt;/P&gt;
&lt;P&gt;I’ve created a &lt;STRONG&gt;&lt;A href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=wpfdatavideos&amp;amp;DownloadId=6509" target=_blank mce_href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=wpfdatavideos&amp;amp;DownloadId=6509"&gt;sample application that you can download from Code Gallery&lt;/A&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;/STRONG&gt; that demonstrates using EF with WPF in a variety of ways including this example so have a look. Also make sure you check out these &lt;A href="http://msdn.microsoft.com/en-us/vbasic/bb466226.aspx#wpfentity" target=_blank mce_href="http://msdn.microsoft.com/en-us/vbasic/bb466226.aspx#wpfentity"&gt;How Do I videos on EF and WPF&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9823270" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Article/default.aspx">Article</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Entity+Framework/default.aspx">Entity Framework</category></item><item><title>New “How Do I” Video Series Released</title><link>http://blogs.msdn.com/bethmassi/archive/2009/07/01/new-how-do-i-video-series-released.aspx</link><pubDate>Thu, 02 Jul 2009 03:28:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9812376</guid><dc:creator>Beth Massi</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9812376.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9812376</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9812376</wfw:comment><description>&lt;p&gt;I just released 3 new videos onto the &lt;a href="http://msdn.microsoft.com/en-us/vbasic/bb466226.aspx#wpfentity" target="_blank"&gt;VB Dev Center&lt;/a&gt; starting a new series on how to do WPF data binding with Entity Framework using &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E&amp;amp;displaylang=en" target="_blank"&gt;Visual Studio 2008 Service Pack 1&lt;/a&gt;. This is a “no frills” WPF series that focuses on data so you won’t see any other tools used besides Visual Studio 2008 SP1 and no flashy animations. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/vbasic/dd776537.aspx"&gt;#1 | How Do I: Get Started with Entity Framework in WPF Applications?&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/vbasic/dd776540.aspx"&gt;#2 | How Do I: Build a WPF Data Entry Form Using Entity Framework?&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/vbasic/dd776544.aspx"&gt;#3 | How Do I: Create a WPF Lookup Combobox using Entity Framework?&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The videos are a bit longer than your normal 5-minute “How Do I” videos but I tried to keep them short by re-using the data access layer I build in the first one. I hope this doesn’t confuse people. Believe me when I say this will get a lot better, &lt;a href="http://blogs.msdn.com/vsdata/archive/tags/WPF/default.aspx" target="_blank"&gt;especially tooling-wise&lt;/a&gt;, in Visual Studio 2010. But this is a good introduction to building WPF data apps against Entity Framework with the version of Visual Studio that is available now! :-) &lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9812376" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Videos/default.aspx">Videos</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Entity+Framework/default.aspx">Entity Framework</category></item><item><title>Good Times at DevTeach, Vancouver</title><link>http://blogs.msdn.com/bethmassi/archive/2009/06/19/good-times-at-devteach-vancouver.aspx</link><pubDate>Sat, 20 Jun 2009 03:24:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9792450</guid><dc:creator>Beth Massi</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9792450.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9792450</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9792450</wfw:comment><description>&lt;p&gt;Last week I spoke at &lt;a href="http://www.devteach.com/" target="_blank"&gt;DevTeach&lt;/a&gt; in Vancouver which was held at the beautiful Four Seasons in downtown. I love this Canadian conference because the attendees are great – super friendly and social, and ask a lot of great questions. I mostly interacted with folks building applications for the government or working as consultants and wanting to freshen up their .NET skills. It was also nice to see a good number of VB developers here. I gave three talks and ended up in the top 3 speakers overall which was great :-). &lt;/p&gt; &lt;p&gt;&lt;em&gt;&lt;strong&gt;Future Directions for Visual Basic and C#&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt; &lt;p&gt;Before the conference I did a joint user’s group talk and about 120 people showed up to see “&lt;em&gt;Future Directions for Visual Basic and C#&lt;/em&gt;” which has also been delivered before at PDC and TechEd by folks on the Language Team. I did a flavor of &lt;a href="http://services.social.microsoft.com/feeds/FeedItem?feedId=c1cf0fd1-95b7-42b9-a6fa-8e48d55c5411&amp;amp;itemId=9db6fd68-220a-4932-8ec0-e4c807499d84&amp;amp;title=TechEd%3a+Future+Directions+for+Visual+Basic&amp;amp;uri=http%3a%2f%2fwww.msteched.com%2fonline%2fview.aspx%3ftid%3d1d3d650b-a6b3-4c98-9240-571866969b89&amp;amp;k=UV75hhA0OqzauUokJoycPxZSxiny%2b1vx2oDW5QVb5%2fw%3d" target="_blank"&gt;Jonathan Aneja’s TechEd talk&lt;/a&gt; but I also included new C# features which I have to say are a welcome relief to me personally. Unfortunately my VM was misbehaving so badly that Visual Studio was running at a snail’s pace. But I joked around and got through it ending up with some good comments and questions. I did the talk again at the conference and my VM was just fine – go figure. As a bonus for the conference attendees I also included a VB REPL demo and it was a hit. Check out &lt;a href="http://services.social.microsoft.com/feeds/FeedItem?feedId=c1cf0fd1-95b7-42b9-a6fa-8e48d55c5411&amp;amp;itemId=9db6fd68-220a-4932-8ec0-e4c807499d84&amp;amp;title=TechEd%3a+Future+Directions+for+Visual+Basic&amp;amp;uri=http%3a%2f%2fwww.msteched.com%2fonline%2fview.aspx%3ftid%3d1d3d650b-a6b3-4c98-9240-571866969b89&amp;amp;k=UV75hhA0OqzauUokJoycPxZSxiny%2b1vx2oDW5QVb5%2fw%3d" target="_blank"&gt;John’s TechEd recording&lt;/a&gt; for variations of the VB demos that I showed. &lt;/p&gt; &lt;p&gt;Most interesting was the group that attended the talk. It was almost a 50/50 split between VB and C# devs in the room with some cross-over (doing both). I even had 3 C++ programmers attend. I started out with all the new VB features, then showed all the new C# features and then finished up with the new features in both. I had a lot of fun with the session, jabbing at both languages here and there and poking fun in places where one was catching up to the other and vice versa. Here’s the breakdown of new stuff in each language:&lt;/p&gt; &lt;table cellspacing="0" cellpadding="2" width="400" border="1"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" width="192"&gt;&lt;strong&gt;Feature &lt;/strong&gt;&lt;/td&gt; &lt;td valign="top" width="106"&gt;&lt;strong&gt;VB10 &lt;/strong&gt;&lt;/td&gt; &lt;td valign="top" width="101"&gt;&lt;strong&gt;C#4&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="192"&gt;&lt;span style="color: black"&gt;Auto-implemented Properties &lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="106"&gt;&lt;span style="color: #00b050"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y &lt;/font&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="101"&gt;&lt;span style="color: #7878de"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y&lt;/font&gt;&lt;/strong&gt; &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="192"&gt;&lt;span style="color: black"&gt;Collection Initializers &lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="106"&gt;&lt;span style="color: #00b050"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y &lt;/font&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="101"&gt;&lt;span style="color: #7878de"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y&lt;/font&gt;&lt;/strong&gt; &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="192"&gt;&lt;span style="color: black"&gt;Multiline &amp;amp; Statement Lambdas &lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="106"&gt;&lt;span style="color: #00b050"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y &lt;/font&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="101"&gt;&lt;span style="color: #7878de"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y&lt;/font&gt;&lt;/strong&gt; &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="192"&gt;&lt;span style="color: black"&gt;Implicit Line Continuation &lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="106"&gt;&lt;span style="color: #00b050"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y &lt;/font&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="101"&gt;N/A&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="192"&gt;&lt;span style="color: black"&gt;Named/Optional Parameters &lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="106"&gt;&lt;span style="color: #7878de"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y&lt;/font&gt;&lt;/strong&gt; &lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="101"&gt;&lt;span style="color: #00b050"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y &lt;/font&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="192"&gt;&lt;span style="color: black"&gt;Late binding support (dynamic) &lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="106"&gt;&lt;span style="color: #7878de"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y&lt;/font&gt;&lt;/strong&gt; &lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="101"&gt;&lt;span style="color: #00b050"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y &lt;/font&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="192"&gt;&lt;span style="color: black"&gt;Omit ref on COM calls &lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="106"&gt;&lt;span style="color: #7878de"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y&lt;/font&gt;&lt;/strong&gt; &lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="101"&gt;&lt;span style="color: #00b050"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y &lt;/font&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="192"&gt;&lt;span style="color: black"&gt;DLR Integration &lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="106"&gt;&lt;span style="color: #00b050"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y &lt;/font&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="101"&gt;&lt;span style="color: #00b050"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y &lt;/font&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="192"&gt;&lt;span style="color: black"&gt;Generic Variance &lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="106"&gt;&lt;span style="color: #00b050"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y &lt;/font&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="101"&gt;&lt;span style="color: #00b050"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y &lt;/font&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="192"&gt;&lt;span style="color: black"&gt;PIA deployment not needed &lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="106"&gt;&lt;span style="color: #00b050"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y &lt;/font&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt; &lt;td valign="top" width="101"&gt;&lt;span style="color: #00b050"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y &lt;/font&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;pre class="code"&gt;&lt;span style="color: #7878de"&gt;&lt;strong&gt;&lt;font size="3"&gt;Y = Already exists in VB9/C#3&lt;/font&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="color: #00b050"&gt;&lt;strong&gt;&lt;font size="3"&gt;&lt;br&gt;Y = New in VB10/C#4&lt;/font&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="color: gray"&gt;&lt;/pre&gt;&lt;/span&gt;
&lt;p&gt;Check out the &lt;a href="http://msdn.microsoft.com/en-us/vstudio/dd238515.aspx" target="_blank"&gt;Visual Studio 2010 Language samples&lt;/a&gt; and language &lt;a href="http://msdn.microsoft.com/en-us/vstudio/dd441784.aspx" target="_blank"&gt;walkthroughs&lt;/a&gt; for details on each of these features.&lt;/p&gt;
&lt;p&gt;The C# crowd seemed in particular to like the Named &amp;amp; Optional parameter support commenting that “It’s useful because it saves me writing code”. I actually showed all of the C# 4 features in one method that demonstrated COM interop with Office lifted from &lt;a href="http://msdn.microsoft.com/en-us/library/dd867746.aspx" target="_blank"&gt;this walkthrough&lt;/a&gt;. The VB crowd was particularly pleased to see no more underscores and auto-implemented properties. And those that commented in the session were pleased to see the language parity. I’m just glad I didn’t get any rotten tomatoes thrown at me from either side. :-)&lt;/p&gt;
&lt;p&gt;Here’s some more resources to check out:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" target="_blank"&gt;Visual Studio 2010 and .NET Framework 4 Beta 1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/dd819153.aspx"&gt;Visual Basic 2010 Resources&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/vcsharp/dd819407.aspx"&gt;Visual C# 2010 Resources&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/vbteam " target="_blank"&gt;VB Team Blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/csharpfaq/" target="_blank"&gt;C# FAQ Blog&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Data Sources and Data Binding with WPF&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I’ve done this talk &lt;a href="http://blogs.msdn.com/bethmassi/archive/2008/12/08/back-from-devteach-montreal.aspx" target="_blank"&gt;many times before&lt;/a&gt; and it’s always a lot of fun. I've been &lt;a href="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx"&gt;blogging&lt;/a&gt; on data binding in WPF as well as doing &lt;a href="http://msdn.microsoft.com/en-us/vbasic/bb466226.aspx#wpfdata"&gt;How Do I videos&lt;/a&gt; for a while now. This talk takes WPF data binding from a Winforms developer perspective and I try to demonstrate that investments made in your Winforms data sources can be used in WPF. The crowd seemed relieved ;-). I also showed the drag-drop data binding in Visual Studio 2010 building a form similar to what &lt;a href="http://blogs.msdn.com/bethmassi/archive/2008/11/26/channel-9-interview-wpf-drag-drop-data-binding-in-visual-studio-2010.aspx"&gt;Milind showed in this Channel 9 interview&lt;/a&gt;. The team has also been blogging heavily about &lt;a href="http://blogs.msdn.com/vsdata/archive/tags/WPF/default.aspx" target="_blank"&gt;WPF data binding in VS2010&lt;/a&gt; on the &lt;a href="http://blogs.msdn.com/vsdata/" target="_blank"&gt;VS Data blog&lt;/a&gt; so check it out. &lt;/p&gt;
&lt;p&gt;Here’s some more resources to check out:&lt;/p&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2008/09/24/data-sources-and-data-binding-in-wpf-talk-in-redmond.aspx"&gt;Data Sources and Data Binding in WPF &lt;/a&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/vbasic/bb466226.aspx#wpfdata"&gt;WPF Forms over Data Videos&lt;/a&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2008/11/26/channel-9-interview-wpf-drag-drop-data-binding-in-visual-studio-2010.aspx"&gt;Channel 9 Interview: WPF Drag-Drop Data Binding in Visual Studio 2010&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/vsdata/archive/tags/WPF/default.aspx" target="_blank"&gt;VS Data Team Blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" target="_blank"&gt;Visual Studio 2010 and .NET Framework 4 Beta 1&lt;/a&gt;&lt;/li&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Conquering XML with LINQ in Visual Basic 9&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This has got to be one of my most favorite talks of all time. I've written a lot &lt;a href="http://blogs.msdn.com/bethmassi/archive/tags/XML/LINQ/Article/default.aspx"&gt;on this topic&lt;/a&gt;. I have been doing this one for a couple years now and what’s great about it is that it never gets old. It’s amazing how many folks are still not aware of XML Literals in VB. Only about 10% of attendees had used them before so I started with the basics and worked my way up into the demos. This talk scored very high for me and I think it’s because I show a lot of practical examples of using XML Literals and LINQ to XML. I didn’t show any betas or unreleased bits either and I think folks appreciated that they could go home and get working with it right away. &lt;/p&gt;
&lt;p&gt;I got through all the demos and showed a good amount of &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c6e744e5-36e9-45f5-8d8c-331df206e0d0&amp;amp;DisplayLang=en"&gt;Open XML SDK&lt;/a&gt; to manipulate Office 2007 documents. I also showed off the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=46B6BF86-E35D-4870-B214-4D7B72B02BF9&amp;amp;displaylang=en"&gt;VSTO Power tools&lt;/a&gt; a bit for viewing the Open XML packages. Amongst the many demos we went through, we built a letter generator from scratch &lt;a href="http://blogs.msdn.com/bethmassi/archive/2008/07/30/accessing-openxml-document-parts-with-the-openxml-sdk.aspx"&gt;like I've shown before here&lt;/a&gt;. I also did my famous &lt;a href="http://blogs.msdn.com/bethmassi/archive/2007/12/03/northwind-meets-virtual-earth-generate-ve-maps-with-linq.aspx"&gt;Virtual Earth demo&lt;/a&gt; that people always enjoy.&lt;/p&gt;
&lt;p&gt;Here’s some more resources to check out:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/tags/LINQ/XML/default.aspx" target="_blank"&gt;My LINQ to XML blog posts &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.code-magazine.com/article.aspx?quickid=0807061" target="_blank"&gt;Sharpening Your Axis with Visual Basic 9&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc947916.aspx" target="_blank"&gt;Dynamic Data Entry With XML Literals&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032374409&amp;amp;EventCategory=5&amp;amp;culture=en-US&amp;amp;CountryCode=US" target="_blank"&gt;Webcast: Working with XML in Visual Basic&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/vbteam " target="_blank"&gt;VB Team Blog&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;I also attended a few sessions myself on MVVM and Silverlight so you may see more of that cranking out of this blog at some point. ;-) I look forward to the next DevTeach! &lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9792450" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Speaking/default.aspx">Speaking</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Community/default.aspx">Community</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/XML/default.aspx">XML</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2010/default.aspx">VS2010</category></item><item><title>WPF Data Binding Samples on Code Gallery</title><link>http://blogs.msdn.com/bethmassi/archive/2009/06/17/wpf-data-binding-samples-on-code-gallery.aspx</link><pubDate>Wed, 17 Jun 2009 22:41:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9770286</guid><dc:creator>Beth Massi</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9770286.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9770286</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9770286</wfw:comment><description>&lt;p&gt;One of the many &lt;a href="http://msdn.microsoft.com/en-us/vstudio/dd238515.aspx" target="_blank"&gt;samples released for Visual Studio 2010 Beta 1&lt;/a&gt; that you should be aware of are examples of WPF data binding against Entity Data Models. You can find some easy to follow samples here: &lt;a href="http://code.msdn.microsoft.com/WPFDatabinding"&gt;&lt;strong&gt;http://code.msdn.microsoft.com/WPFDatabinding&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This sample demonstrates how to create a WPF Forms solution that checks user input with validation code, demonstrates common controls such as DataGrid and ComboBox, and shows typical data manipulation including create, read, update, and delete. The sample solution is available in both Visual Basic and C# and is intended for use with Visual Studio 2010 Beta 1 and with the .NET Framework 3.5.&amp;#160; In the future, we will release a sample that performs with the .Net Framework 4.0 Beta.&lt;/p&gt;  &lt;p&gt;Check out the &lt;a href="http://blogs.msdn.com/vsdata" target="_blank"&gt;VS Data Team blog&lt;/a&gt; for more information on WPF data-binding and Karl’s blog on a great &lt;a href="http://karlshifflett.wordpress.com/2009/06/10/wpf-sample-series-listbox-grouping-sorting-subtotals-and-collapsible-regions/" target="_blank"&gt;WPF sample series&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9770286" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Data/default.aspx">Data</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2010/default.aspx">VS2010</category></item><item><title>Visual Studio 2010 Beta 1 – Everyone can download and play today!</title><link>http://blogs.msdn.com/bethmassi/archive/2009/05/20/visual-studio-2010-beta-1-everyone-can-download-and-play-today.aspx</link><pubDate>Wed, 20 May 2009 20:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9632575</guid><dc:creator>Beth Massi</dc:creator><slash:comments>11</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9632575.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9632575</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9632575</wfw:comment><description>&lt;P&gt;Here it is folks, Visual Studio 2010 Beta 1 has been released to the public today. Check out the &lt;A href="http://go.microsoft.com/fwlink/?LinkID=151797" mce_href="http://go.microsoft.com/fwlink/?LinkID=151797"&gt;&lt;STRONG&gt;Visual Studio 2010 and .NET Framework 4 Beta 1 site&lt;/STRONG&gt;&lt;/A&gt; to download the Beta, submit product feedback on the &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/category/VSPreRelease,netdevelopmentprerelease,visualstudioprerelease,vstsprerelease" target=_blank mce_href="http://social.msdn.microsoft.com/Forums/en-US/category/VSPreRelease,netdevelopmentprerelease,visualstudioprerelease,vstsprerelease"&gt;Beta 1 Forums&lt;/A&gt;, report bugs on &lt;A href="http://go.microsoft.com/fwlink/?LinkID=151484" target=_blank mce_href="http://go.microsoft.com/fwlink/?LinkID=151484"&gt;Connect&lt;/A&gt;, and find additional information. Also visit the &lt;A href="http://msdn.microsoft.com/en-us/vstudio/dd441784.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/vstudio/dd441784.aspx"&gt;Beta 1 walkthroughs page&lt;/A&gt; for information on how to use the new features and download the &lt;A href="http://msdn.microsoft.com/en-us/vstudio/dd238515.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/vstudio/dd238515.aspx"&gt;Visual Studio 2010 Samples&lt;/A&gt;. There’s also some good language-focused resources on the &lt;A href="http://msdn.microsoft.com/en-us/vbasic/dd819153.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/vbasic/dd819153.aspx"&gt;Visual Basic 2010&lt;/A&gt; and &lt;A href="http://msdn.microsoft.com/en-us/vcsharp/dd819407.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/vcsharp/dd819407.aspx"&gt;C# 2010&lt;/A&gt; that are hanging off the Developer Centers. &lt;/P&gt;
&lt;P&gt;Some of my favorite features include those around the &lt;A href="http://windowsclient.net/wpfdesigner" target=_blank mce_href="http://windowsclient.net/wpfdesigner"&gt;WPF Designer&lt;/A&gt; and the Data Sources Window which now supports the same drag-drop RAD experience of Winforms in WPF applications:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd465159(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd465159(VS.100).aspx"&gt;Walkthrough: Binding WPF Controls to an Entity Data Model&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd547149(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd547149(VS.100).aspx"&gt;Walkthrough: Binding WPF Controls to a Dataset&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd465161(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd465161(VS.100).aspx"&gt;Walkthrough: Binding WPF Controls to an ADO.NET Data Service&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd465158(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd465158(VS.100).aspx"&gt;Walkthrough: Displaying Related Data in a WPF Application&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;For Office solutions, check out the &lt;A href="http://msdn.microsoft.com/en-us/library/dd234217(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd234217(VS.100).aspx"&gt;Advanced Office Solution Deployment&lt;/A&gt; topic in the library and the &lt;A href="http://blogs.msdn.com/vsto/" target=_blank mce_href="http://blogs.msdn.com/vsto/"&gt;VSTO Team blog&lt;/A&gt; for some cool new Office client features:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd465290(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd465290(VS.100).aspx"&gt;Walkthrough: Deploying Multiple Office Solutions in a Single ClickOnce Installer&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd465291(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd465291(VS.100).aspx"&gt;Walkthrough: Copying a Document to the End User Computer after a ClickOnce Installation&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Take a look through the &lt;A href="http://msdn.microsoft.com/en-us/library/dd547188(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd547188(VS.100).aspx"&gt;Visual Studio 2010 Product Highlights&lt;/A&gt; and &lt;A href="http://msdn.microsoft.com/en-us/library/bb386063(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb386063(VS.100).aspx"&gt;What's New in Visual Studio 2010&lt;/A&gt; for more info on other new features including &lt;A href="http://msdn.microsoft.com/en-us/library/z4y0hsax(VS.100).aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/z4y0hsax(VS.100).aspx"&gt;multi-monitor&lt;/A&gt; – YUMMY! :-)&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;New Team Bloggers&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;I’d also like to introduce the “come-back” of the &lt;A href="http://blogs.msdn.com/vsdata/" target=_blank mce_href="http://blogs.msdn.com/vsdata/"&gt;Visual Studio Data team blog&lt;/A&gt;. We’ve got a lot of new faces on the team that are building some amazing tools in Visual Studio to help you build business applications. They’ll be posting a lot of great &lt;A href="http://blogs.msdn.com/vsdata/archive/tags/VS2010/default.aspx" target=_blank mce_href="http://blogs.msdn.com/vsdata/archive/tags/VS2010/default.aspx"&gt;VS 2010 content here&lt;/A&gt;.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Visual Studio 2010 Beta 1 resources:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://go.microsoft.com/fwlink/?LinkID=151797" mce_href="http://go.microsoft.com/fwlink/?LinkID=151797"&gt;&lt;STRONG&gt;Visual Studio 2010 and .NET Framework 4 Beta 1 site&lt;/STRONG&gt;&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://go.microsoft.com/?linkid=9665216" mce_href="http://go.microsoft.com/?linkid=9665216"&gt;Visual Studio 2010 and .NET Framework 4.0 Training Kit &lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/vstudio/dd238515.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/vstudio/dd238515.aspx"&gt;Visual Studio 2010 Samples&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/vstudio/dd441784.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/vstudio/dd441784.aspx"&gt;Visual Studio 2010 Beta 1 Walkthroughs&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://windowsclient.net/wpfdesigner" mce_href="http://windowsclient.net/wpfdesigner"&gt;WPF and Silverlight Designer Walkthroughs&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/bb386063(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb386063(VS.100).aspx"&gt;What's New in Visual Studio 2010&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd547188(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd547188(VS.100).aspx"&gt;Visual Studio 2010 Product Highlights&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/vbasic/dd819153.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/vbasic/dd819153.aspx"&gt;Visual Basic 2010&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/vcsharp/dd819407.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/vcsharp/dd819407.aspx"&gt;C# 2010&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd831853(VS.100).aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/dd831853(VS.100).aspx"&gt;VS 2010 Library&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://channel9.msdn.com/tags/Visual%20Studio%202010/"&gt;Visual Studio 2010 on Channel 9&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;My recommended blogs on VS 2010:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/vsdata/archive/tags/VS2010/default.aspx" target=_blank mce_href="http://blogs.msdn.com/vsdata/archive/tags/VS2010/default.aspx"&gt;Visual Studio Data Team&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/vsto/archive/tags/VS2010/default.aspx" target=_blank mce_href="http://blogs.msdn.com/vsto/archive/tags/VS2010/default.aspx"&gt;VSTO Team&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/vbteam/archive/tags/VB2010/default.aspx" target=_blank mce_href="http://blogs.msdn.com/vbteam/archive/tags/VB2010/default.aspx"&gt;Visual Basic Team&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/jasonz/" target=_blank mce_href="http://blogs.msdn.com/jasonz/"&gt;Jason Zander&lt;/A&gt; (executive blog) &lt;/LI&gt;
&lt;LI&gt;and &lt;A href="http://blogs.msdn.com/bethmassi/archive/tags/VS2010/default.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/tags/VS2010/default.aspx"&gt;Me&lt;/A&gt; ;-)&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9632575" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Data/default.aspx">Data</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2010/default.aspx">VS2010</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VSTO/default.aspx">VSTO</category></item><item><title>Using the WPF ObservableCollection with EF Entities</title><link>http://blogs.msdn.com/bethmassi/archive/2009/05/08/using-the-wpf-observablecollection-with-ef-entities.aspx</link><pubDate>Sat, 09 May 2009 01:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9597952</guid><dc:creator>Beth Massi</dc:creator><slash:comments>12</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9597952.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9597952</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9597952</wfw:comment><description>&lt;P&gt;The &lt;A href="http://msdn.microsoft.com/en-us/library/ms668604.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms668604.aspx"&gt;ObservableCollection&lt;/A&gt; is a special WPF collection that provides proper notifications to the UI when items are added, removed, or the list is refreshed because it implements &lt;A href="http://msdn.microsoft.com/en-us/library/system.collections.specialized.inotifycollectionchanged.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.collections.specialized.inotifycollectionchanged.aspx"&gt;INotifyCollectionChanged&lt;/A&gt;. It’s common to use this collection (or inherit from it) to contain your business objects you want to bind to in WPF.&amp;nbsp; &lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Class &lt;/SPAN&gt;Window1&lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;    Private &lt;/SPAN&gt;CustomerData &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;ObservableCollection(&lt;SPAN style="COLOR: blue"&gt;Of &lt;/SPAN&gt;Customer)&lt;/PRE&gt;
&lt;P&gt;You can then set up a &lt;A href="http://msdn.microsoft.com/en-us/library/system.windows.data.collectionviewsource.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.windows.data.collectionviewsource.aspx"&gt;CollectionViewSource&lt;/A&gt; and use it’s View property to get a reference to the &lt;A href="http://msdn.microsoft.com/en-us/library/system.windows.data.listcollectionview.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.windows.data.listcollectionview.aspx"&gt;ListCollectionView&lt;/A&gt; in order to add and remove items instead of working with the source collection directly. This decouples your data source (and therefore any collection logic) from the form itself making it much easier to change sources later. I’ve showed &lt;A href="http://blogs.msdn.com/bethmassi/archive/2008/11/07/loading-data-and-binding-controls-in-wpf-with-collectionviewsource.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2008/11/07/loading-data-and-binding-controls-in-wpf-with-collectionviewsource.aspx"&gt;how to use CollectionViewSources before&lt;/A&gt; but basically you just declare them in the Window.Resources section and bind to them in XAML: &lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Window &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Class&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Window1"
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Title&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Window1" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="282" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="440" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Window1"&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Window.Resources&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
      &lt;STRONG&gt;  &amp;lt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: #a31515"&gt;CollectionViewSource &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Key&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;STRONG&gt;="CustomerSource" /&amp;gt;&lt;/STRONG&gt;
    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Window.Resources&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;DataContext&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: red"&gt;Source&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;={&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;CustomerSource&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;}"&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;And then you can set the Source property in code to your collection and obtain the ListCollectionView. &lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;customerSource = &lt;SPAN style="COLOR: blue"&gt;CType&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.Resources(&lt;SPAN style="COLOR: #a31515"&gt;"CustomerSource"&lt;/SPAN&gt;), CollectionViewSource)
customerSource.&lt;STRONG&gt;Source&lt;/STRONG&gt; = &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.CustomerData

&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.View = &lt;SPAN style="COLOR: blue"&gt;CType&lt;/SPAN&gt;(customerSource.&lt;STRONG&gt;View&lt;/STRONG&gt;, ListCollectionView)&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;Then you use the View to add and remove items from the collection and the UI will update properly: &lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Private Sub &lt;/SPAN&gt;btnDelete_Click() &lt;SPAN style="COLOR: blue"&gt;Handles &lt;/SPAN&gt;btnDelete.Click
       &lt;SPAN style="COLOR: blue"&gt;If Me&lt;/SPAN&gt;.View.CurrentPosition &amp;gt; -1 &lt;SPAN style="COLOR: blue"&gt;Then
           &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;'removes the currently selected customer from the underlying collection 
           &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.View.RemoveAt(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.View.CurrentPosition)
       &lt;SPAN style="COLOR: blue"&gt;End If
   End Sub

   Private Sub &lt;/SPAN&gt;btnAdd_Click() &lt;SPAN style="COLOR: blue"&gt;Handles &lt;/SPAN&gt;btnAdd.Click
       &lt;SPAN style="COLOR: green"&gt;'adds a new customer to the underlying collection 
       &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;customer = &lt;SPAN style="COLOR: blue"&gt;CType&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.View.AddNew, Customer)
       &lt;SPAN style="COLOR: green"&gt;'do something with customer if needed...
       &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.View.CommitNew()
   &lt;SPAN style="COLOR: blue"&gt;End Sub&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;Calling these methods on the ListCollectionView will execute the &lt;A href="http://msdn.microsoft.com/en-us/library/ms654928.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms654928.aspx"&gt;InsertItem&lt;/A&gt; and &lt;A href="http://msdn.microsoft.com/en-us/library/ms654938.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms654938.aspx"&gt;RemoveItem&lt;/A&gt; methods on the ObservableCollection.&lt;/P&gt;
&lt;P&gt;Now if you are using an &lt;A href="http://msdn.microsoft.com/en-us/library/bb387122.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/bb387122.aspx"&gt;Entity Data Model (EDM)&lt;/A&gt; the designer in Visual Studio 2008 SP1 will generate entity classes for you that you can also bind to in your UI. Access to these entities is done through the &lt;A href="http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.aspx"&gt;ObjectContext&lt;/A&gt; and the designer also creates a class for you that inherits from this when you create the EDM. It is named something like xxxEntites. (For instance, in Visual Studio 2008 SP1 “Add New Item” and select ADO.NET Entity Data Model and name it Northwind.edmx. Generate from Database and select Northwind. Select all the tables and then the designer will generate an ObjectContext called NorthwindEntities and entity classes based on the tables in the database.)&lt;/P&gt;
&lt;P&gt;Because the ObjectContext is what tracks changes on entities you can place entities inside an ObservableCollection but in order for the ObjectContext to be notified that adds and deletes need to be tracked you need to write a bit of code. The easiest thing to do is to create your own class that inherits from ObservableCollection and override the InsertItem and RemoveItem methods so that you can tell the ObjectContext to either add or delete the entity which will ultimately execute against the database. In the constructor pass a reference to the ObjectContext. You can also pass in any collection of entities, say from a LINQ query, and then add them to the ObservableCollection. For example:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Imports &lt;/SPAN&gt;NorthwindDAL
&lt;SPAN style="COLOR: blue"&gt;Imports &lt;/SPAN&gt;System.Collections.ObjectModel

&lt;SPAN style="COLOR: blue"&gt;Public Class &lt;/SPAN&gt;CustomerCollection
    &lt;SPAN style="COLOR: blue"&gt;Inherits &lt;/SPAN&gt;ObservableCollection(&lt;SPAN style="COLOR: blue"&gt;Of &lt;/SPAN&gt;Customer)

   &lt;SPAN style="COLOR: blue"&gt; Private &lt;/SPAN&gt;_context &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;NorthwindEntities
    &lt;SPAN style="COLOR: blue"&gt;Public ReadOnly Property &lt;/SPAN&gt;Context() &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;NorthwindEntities
        &lt;SPAN style="COLOR: blue"&gt;Get
            Return &lt;/SPAN&gt;_context
        &lt;SPAN style="COLOR: blue"&gt;End Get
    End Property

    Sub New&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;customers &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;IEnumerable(&lt;SPAN style="COLOR: blue"&gt;Of &lt;/SPAN&gt;Customer), &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;context &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;NorthwindEntities)
        &lt;SPAN style="COLOR: blue"&gt;MyBase&lt;/SPAN&gt;.New(customers)&lt;BR&gt;       &lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;_context = context
    &lt;SPAN style="COLOR: blue"&gt;End Sub

    Protected Overrides Sub &lt;/SPAN&gt;InsertItem(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;index &lt;SPAN style="COLOR: blue"&gt;As Integer&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;item &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Customer)
   &lt;SPAN style="COLOR: blue"&gt;     Me&lt;/SPAN&gt;.Context.AddToCustomers(item)
   &lt;SPAN style="COLOR: blue"&gt;     MyBase&lt;/SPAN&gt;.InsertItem(index, item)
    &lt;SPAN style="COLOR: blue"&gt;End Sub

    Protected Overrides Sub &lt;/SPAN&gt;RemoveItem(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;index &lt;SPAN style="COLOR: blue"&gt;As Integer&lt;/SPAN&gt;)
        &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.Context.DeleteObject(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;(index))
        &lt;SPAN style="COLOR: blue"&gt;MyBase&lt;/SPAN&gt;.RemoveItem(index)
    &lt;SPAN style="COLOR: blue"&gt;End Sub

End Class&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;Then you can use the collection on your WPF form instead like so:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Imports &lt;/SPAN&gt;NorthwindDAL

&lt;SPAN style="COLOR: blue"&gt;Class &lt;/SPAN&gt;Window1
    &lt;SPAN style="COLOR: blue"&gt;Private &lt;/SPAN&gt;db &lt;SPAN style="COLOR: blue"&gt;As New &lt;/SPAN&gt;NorthwindEntities
    &lt;SPAN style="COLOR: blue"&gt;Private &lt;/SPAN&gt;CustomerData &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;CustomerCollection
    &lt;SPAN style="COLOR: blue"&gt;Private &lt;/SPAN&gt;View &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;ListCollectionView

    &lt;SPAN style="COLOR: blue"&gt;Private Sub &lt;/SPAN&gt;Window1_Loaded() &lt;SPAN style="COLOR: blue"&gt;Handles MyBase&lt;/SPAN&gt;.Loaded

        &lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;results = &lt;SPAN style="COLOR: blue"&gt;From &lt;/SPAN&gt;c &lt;SPAN style="COLOR: blue"&gt;In &lt;/SPAN&gt;db.Customers _
                      &lt;SPAN style="COLOR: blue"&gt;Where &lt;/SPAN&gt;c.City.ToLower = &lt;SPAN style="COLOR: #a31515"&gt;"seattle" &lt;/SPAN&gt;_
                      &lt;SPAN style="COLOR: blue"&gt;Order By &lt;/SPAN&gt;c.LastName, c.FirstName _
                      &lt;SPAN style="COLOR: blue"&gt;Select &lt;/SPAN&gt;c

&lt;STRONG&gt;        &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.CustomerData = &lt;SPAN style="COLOR: blue"&gt;New &lt;/SPAN&gt;CustomerCollection(results, db)&lt;/STRONG&gt;&lt;/PRE&gt;&lt;PRE class=code&gt;        &lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;customerSource = &lt;SPAN style="COLOR: blue"&gt;CType&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.Resources(&lt;SPAN style="COLOR: #a31515"&gt;"CustomerSource"&lt;/SPAN&gt;), CollectionViewSource)
        customerSource.Source = &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.CustomerData
        &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.View = &lt;SPAN style="COLOR: blue"&gt;CType&lt;/SPAN&gt;(customerSource.View, ListCollectionView)
    &lt;SPAN style="COLOR: blue"&gt;End Sub&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=code&gt;    &lt;SPAN style="COLOR: blue"&gt;Private Sub &lt;/SPAN&gt;btnSave_Click() &lt;SPAN style="COLOR: blue"&gt;Handles &lt;/SPAN&gt;btnSave.Click
        &lt;SPAN style="COLOR: blue"&gt;Try
            &lt;/SPAN&gt;db.SaveChanges()
            MsgBox(&lt;SPAN style="COLOR: #a31515"&gt;"Customer data was saved."&lt;/SPAN&gt;)
        &lt;SPAN style="COLOR: blue"&gt;Catch &lt;/SPAN&gt;ex &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Exception
            MsgBox(ex.ToString())
        &lt;SPAN style="COLOR: blue"&gt;End Try
    End Sub&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;    Private Sub &lt;/SPAN&gt;btnDelete_Click() &lt;SPAN style="COLOR: blue"&gt;Handles &lt;/SPAN&gt;btnDelete.Click
        &lt;SPAN style="COLOR: blue"&gt;If Me&lt;/SPAN&gt;.View.CurrentPosition &amp;gt; -1 &lt;SPAN style="COLOR: blue"&gt;Then
&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;            &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.View.RemoveAt(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.View.CurrentPosition)
        &lt;SPAN style="COLOR: blue"&gt;End If
    End Sub

    Private Sub &lt;/SPAN&gt;btnAdd_Click() &lt;SPAN style="COLOR: blue"&gt;Handles &lt;/SPAN&gt;btnAdd.Click
&lt;SPAN style="COLOR: blue"&gt;        Dim &lt;/SPAN&gt;customer = &lt;SPAN style="COLOR: blue"&gt;CType&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.View.AddNew, Customer)
        &lt;SPAN style="COLOR: green"&gt;'do something with customer if needed...
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.View.CommitNew()
    &lt;SPAN style="COLOR: blue"&gt;End Sub&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;End Class&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Now any updates, adds or deletes you make in the UI will be propagated to the database through the Entity Framework.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9597952" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Article/default.aspx">Article</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Data/default.aspx">Data</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Entity+Framework/default.aspx">Entity Framework</category></item><item><title>Notifying the UI when Entity References Change in Lookup Comboboxes</title><link>http://blogs.msdn.com/bethmassi/archive/2009/05/04/notifying-the-ui-when-entity-references-change-in-lookup-comboboxes.aspx</link><pubDate>Tue, 05 May 2009 05:51:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9587373</guid><dc:creator>Beth Massi</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9587373.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9587373</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9587373</wfw:comment><description>&lt;p&gt;Last week &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/04/30/data-binding-wpf-lookup-combobox-values-to-ef-entities.aspx" target="_blank"&gt;I wrote about how to data bind WPF lookup comboboxes to entities&lt;/a&gt; returned from the Entity Framework. I described that the key to this type of binding is setting the SelectedItem to the object reference itself on the navigation property instead of setting SelectedValue and SelectedValuePath as in the case when you have foreign key scalar properties like LINQ to SQL classes or DataTables.&lt;/p&gt;  &lt;p&gt;However, depending on your UI, you may need a notification to fire when the entity reference changes. By default this doesn’t happen with entities generated by the &lt;a href="http://msdn.microsoft.com/en-us/library/bb738482.aspx" target="_blank"&gt;EF designer&lt;/a&gt;. Only scalar properties raise change notifications. For instance, going back to our Customer (1)—(*) Order example, the Order entity has a reference to its Customer parent as specified by the navigation property:&lt;/p&gt;  &lt;p&gt;&lt;img src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/DataBindingWPFLookupComboboxValuestoEFEn_F345/image_6.png" /&gt; &lt;/p&gt;  &lt;p&gt;In the database there is a foreign key relationship on CustomerID and that is inferred here by EF. If you look at the Order class that is generated you will see only change notifications raised on the scalar properties, not the navigation properties. For instance, if we take a look at a scalar property that is generated you will see the change notification partial methods generated as well:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Partial Public Class &lt;/span&gt;Order
    &lt;span style="color: blue"&gt;Inherits Global&lt;/span&gt;.System.Data.Objects.DataClasses.EntityObject&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;.
    &lt;span style="color: blue"&gt;Public Property &lt;/span&gt;OrderID() &lt;span style="color: blue"&gt;As Integer
        Get
            Return Me&lt;/span&gt;._OrderID
        &lt;span style="color: blue"&gt;End Get
        Set
            Me&lt;/span&gt;.OnOrderIDChanging(value)
            &lt;span style="color: blue"&gt;Me&lt;/span&gt;.ReportPropertyChanging(&lt;span style="color: #a31515"&gt;&amp;quot;OrderID&amp;quot;&lt;/span&gt;)
            &lt;span style="color: blue"&gt;Me&lt;/span&gt;._OrderID = StructuralObject.SetValidValue(value)
            &lt;span style="color: blue"&gt;Me&lt;/span&gt;.ReportPropertyChanged(&lt;span style="color: #a31515"&gt;&amp;quot;OrderID&amp;quot;&lt;/span&gt;)
            &lt;span style="color: blue"&gt;Me&lt;/span&gt;.OnOrderIDChanged
        &lt;span style="color: blue"&gt;End Set
    End Property
    Private &lt;/span&gt;_OrderID &lt;span style="color: blue"&gt;As Integer
    &lt;br /&gt;    Partial Private Sub &lt;/span&gt;OnOrderIDChanging(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As Integer&lt;/span&gt;)
    &lt;span style="color: blue"&gt;End Sub
    &lt;br /&gt;    Partial Private Sub &lt;/span&gt;OnOrderIDChanged()
    &lt;span style="color: blue"&gt;End Sub
&lt;/span&gt;&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;.&lt;/pre&gt;

&lt;p&gt;EF entities that are generated by the designer inherit from &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.objects.dataclasses.entityobject.aspx" target="_blank"&gt;EntityObject&lt;/a&gt; that in turn inherits from &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.objects.dataclasses.structuralobject.aspx" target="_blank"&gt;StructuralObject&lt;/a&gt; that implements&amp;#160; &lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx" target="_blank"&gt;INotifyPropertyChanged&lt;/a&gt;. This interface is necessary for notifying the UI (WPF and Winforms) that data bound controls should refresh their value. So say you programmatically change a scalar property then any controls bound to that property will be refreshed with the new value automatically. Or in many cases you have a UI with multiple controls bound to the same property. If the user makes a change to one control, the rest update automatically. &lt;/p&gt;

&lt;p&gt;However this notification isn’t generated on entity references. Which means that if you have a lookup combobox set up &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/04/30/data-binding-wpf-lookup-combobox-values-to-ef-entities.aspx" target="_blank"&gt;like I described in last week’s post&lt;/a&gt; and also have another control bound to the same Customer navigation property, then it won’t refresh properly. &lt;/p&gt;

&lt;p&gt;For instance, say we have an Order form with a combobox &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/04/30/data-binding-wpf-lookup-combobox-values-to-ef-entities.aspx" target="_blank"&gt;set up like before&lt;/a&gt;, where the SelectedItem is bound to the Customer property (SelectedItem=&amp;quot;{Binding Path=Customer}&amp;quot;), but we also have a listbox that shows OrderDate, Customer.LastName, Customer.FirstName:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/NotifyingtheUIwhenEntityReferencesChange_1085D/image_2.png"&gt;&lt;img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="302" alt="image" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/NotifyingtheUIwhenEntityReferencesChange_1085D/image_thumb.png" width="468" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ListBox &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Row&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ListBox1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;ItemsSource&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;IsSynchronizedWithCurrentItem&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;True&amp;quot;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ItemsControl.ItemTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;StackPanel &lt;/span&gt;&lt;span style="color: red"&gt;Orientation&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Horizontal&amp;quot;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;60&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;=OrderDate, &lt;/span&gt;&lt;span style="color: red"&gt;StringFormat&lt;/span&gt;&lt;span style="color: blue"&gt;='d'}&amp;quot; /&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;=Customer.LastName}&amp;quot; /&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;5&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;, &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;=Customer.FirstName}&amp;quot; /&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;StackPanel&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ItemsControl.ItemTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;If the user changes the OrderDate then that change will automatically be reflected in the listbox. But if the user changes the Customer in the dropdown combobox then it will NOT update the listbox because a change notification is not raised on Customer. What’s also interesting is if you look at that part of the generated Order entity then you will actually see &lt;strong&gt;two&lt;/strong&gt; properties, one we expect called Customer and one called CustomerReference:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;.&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;Public Property &lt;/span&gt;Customer() &lt;span style="color: blue"&gt;As &lt;/span&gt;Customer
    &lt;span style="color: blue"&gt;Get
        Return CType&lt;/span&gt;(&lt;span style="color: blue"&gt;Me&lt;/span&gt;, IEntityWithRelationships).RelationshipManager. _
        GetRelatedReference(&lt;span style="color: blue"&gt;Of &lt;/span&gt;Customer)(&lt;span style="color: #a31515"&gt;&amp;quot;OMSModel.FK_Orders_Customer&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;Customer&amp;quot;&lt;/span&gt;).Value
    &lt;span style="color: blue"&gt;End Get
    Set&lt;/span&gt;(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As &lt;/span&gt;Customer)
        &lt;span style="color: blue"&gt;CType&lt;/span&gt;(&lt;span style="color: blue"&gt;Me&lt;/span&gt;, IEntityWithRelationships).RelationshipManager. _
        GetRelatedReference(&lt;span style="color: blue"&gt;Of &lt;/span&gt;Customer)(&lt;span style="color: #a31515"&gt;&amp;quot;OMSModel.FK_Orders_Customer&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;Customer&amp;quot;&lt;/span&gt;).Value = value
    &lt;span style="color: blue"&gt;End Set
End Property&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;.
Public Property &lt;/span&gt;CustomerReference() &lt;span style="color: blue"&gt;As &lt;/span&gt;EntityReference(&lt;span style="color: blue"&gt;Of &lt;/span&gt;Customer)
    &lt;span style="color: blue"&gt;Get
        Return CType&lt;/span&gt;(&lt;span style="color: blue"&gt;Me&lt;/span&gt;, IEntityWithRelationships).RelationshipManager. _
        GetRelatedReference(&lt;span style="color: blue"&gt;Of &lt;/span&gt;Customer)(&lt;span style="color: #a31515"&gt;&amp;quot;OMSModel.FK_Orders_Customer&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;Customer&amp;quot;&lt;/span&gt;)
    &lt;span style="color: blue"&gt;End Get
    Set&lt;/span&gt;(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As &lt;/span&gt;EntityReference(&lt;span style="color: blue"&gt;Of &lt;/span&gt;Customer))
        &lt;span style="color: blue"&gt;If &lt;/span&gt;(&lt;span style="color: blue"&gt;Not &lt;/span&gt;(value) &lt;span style="color: blue"&gt;Is Nothing&lt;/span&gt;) &lt;span style="color: blue"&gt;Then
            CType&lt;/span&gt;(&lt;span style="color: blue"&gt;Me&lt;/span&gt;, IEntityWithRelationships).RelationshipManager. _
            InitializeRelatedReference(&lt;span style="color: blue"&gt;Of &lt;/span&gt;Customer)(&lt;span style="color: #a31515"&gt;&amp;quot;OMSModel.FK_Orders_Customer&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;Customer&amp;quot;&lt;/span&gt;, value)
        &lt;span style="color: blue"&gt;End If
    End Set
End Property&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;The Customer property is a navigation property to the parent Customer entity itself as we expect. The CustomerReference is an &lt;a href="http://msdn.microsoft.com/en-us/library/bb297956.aspx" target="_blank"&gt;EntityReference&lt;/a&gt; class. This class describes the &lt;strong&gt;relationship&lt;/strong&gt; between the Order and Customer. It also defines an event called &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.objects.dataclasses.relatedend.associationchanged.aspx" target="_blank"&gt;AssociationChanged&lt;/a&gt; that you can handle to notify the UI properly when the reference changes. When you change the reference this event will fire twice, first to remove the old reference and then again to add the new one. You can easily extend the Order partial class by creating another &lt;a href="http://msdn.microsoft.com/en-us/library/yfzd5350.aspx" target="_blank"&gt;Partial Class declaration&lt;/a&gt; for Order in the same namespace (which is automatically imported in VB) and then calling the appropriate property change notifications:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.ComponentModel

&lt;span style="color: blue"&gt;Partial Public Class &lt;/span&gt;Order
    &lt;span style="color: blue"&gt;Sub New&lt;/span&gt;()
        &lt;span style="color: blue"&gt;MyBase&lt;/span&gt;.New()
        &lt;span style="color: blue"&gt;AddHandler Me&lt;/span&gt;.CustomerReference.AssociationChanged, &lt;span style="color: blue"&gt;AddressOf &lt;/span&gt;Customer_AssociationChanged
    &lt;span style="color: blue"&gt;End Sub

    Private Sub &lt;/span&gt;Customer_AssociationChanged(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;sender &lt;span style="color: blue"&gt;As Object&lt;/span&gt;, _
                                            &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;e &lt;span style="color: blue"&gt;As &lt;/span&gt;CollectionChangeEventArgs)
        &lt;span style="color: blue"&gt;If &lt;/span&gt;e.Action = CollectionChangeAction.Remove &lt;span style="color: blue"&gt;Then
            &lt;/span&gt;OnPropertyChanging(&lt;span style="color: #a31515"&gt;&amp;quot;Customer&amp;quot;&lt;/span&gt;)
        &lt;span style="color: blue"&gt;Else
            &lt;/span&gt;OnPropertyChanged(&lt;span style="color: #a31515"&gt;&amp;quot;Customer&amp;quot;&lt;/span&gt;)
        &lt;span style="color: blue"&gt;End If
    End Sub
End Class&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;So now we can change the Customer in the dropdown and the UI will be notified properly. Sweet. For more information on Entity Framework and data binding &lt;a href="http://msdn.microsoft.com/en-us/library/bb738469.aspx" target="_blank"&gt;see this topic in the MSDN library&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9587373" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Article/default.aspx">Article</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Data/default.aspx">Data</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Entity+Framework/default.aspx">Entity Framework</category></item><item><title>Data Binding WPF Lookup Combobox Values to EF Entities</title><link>http://blogs.msdn.com/bethmassi/archive/2009/04/30/data-binding-wpf-lookup-combobox-values-to-ef-entities.aspx</link><pubDate>Thu, 30 Apr 2009 17:57:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9576176</guid><dc:creator>Beth Massi</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9576176.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9576176</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9576176</wfw:comment><description>&lt;p&gt;It’s extremely common to have to hook up lookup tables on your data entry forms in order to populate foreign keys in a database. I’ve talked about how to do this in Winforms and WPF with Datasets and LINQ to SQL before:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/vbasic/cc788742.aspx" target="_blank"&gt;How Do I: Create a Lookup Combobox in WPF?&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/vbasic/dd239277.aspx" target="_blank"&gt;How Do I: Create a Master-Detail Data Entry Form in WPF?&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/vbasic/bb643829.aspx" target="_blank"&gt;How Do I: Create Lookup Lists?&lt;/a&gt;&amp;#160; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2008/02/07/creating-lookup-lists-with-linq-to-sql.aspx"&gt;Creating Lookup Lists with LINQ to SQL&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2008/02/06/related-data-binding-and-comboboxes-with-linq-to-sql.aspx"&gt;Related Data Binding and ComboBoxes with LINQ to SQL&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2007/04/25/tips-on-related-data-binding-and-comboboxes.aspx"&gt;Tips on Related Data Binding and ComboBoxes&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The common theme between all of these is that the data sources, either the LINQ to SQL classes or the DataTables that we bind to, uses a navigation path based on the foreign key and that foreign key is exposed as a property (or DataColumn). For instance if we have a Customer related to Orders we would have a CustomerID property on Orders. &lt;/p&gt;  &lt;p&gt;DataSets (like databases) rely on this type of navigation. So when you want to find the parent Customer of an Order you have to know the relation. Using typed datasets helps you more but you still end up having to know the details of relationships and foreign keys of the DataSet. That’s why people who are familiar with databases are usually comfortable with working with DataSets.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/DataBindingWPFLookupComboboxValuestoEFEn_F345/image_2.png"&gt;&lt;img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="236" alt="image" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/DataBindingWPFLookupComboboxValuestoEFEn_F345/image_thumb.png" width="587" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;LINQ to SQL classes also include navigation properties as direct object references and collections. So they have both the foreign key and the navigation properties. Customer will have a collection of Orders and Order will have a reference back to Customer but the classes also contain the CustomerID property. This isn’t “pure” I suppose but it does make data binding and subsequent saves back to the database pretty much a no brainer. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/DataBindingWPFLookupComboboxValuestoEFEn_F345/image_4.png"&gt;&lt;img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="242" alt="image" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/DataBindingWPFLookupComboboxValuestoEFEn_F345/image_thumb_1.png" width="553" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;For instance say I want to hook up a lookup combobox using a LINQ to SQL class on an Order with a reference to Customer. I want to display a list of Customers the user can pick from and that Customer should be associated with that Order. It’s pretty straight forward and works the same with DataTables.&lt;/p&gt;  &lt;p&gt;XAML:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Window.Resources&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;CollectionViewSource &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;OrdersSource&amp;quot; /&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;CollectionViewSource &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;CustomerLookup&amp;quot; /&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Window.Resources&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Row&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Grid1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;DataContext&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Source&lt;/span&gt;&lt;span style="color: blue"&gt;={&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource &lt;/span&gt;&lt;span style="color: red"&gt;OrdersSource&lt;/span&gt;&lt;span style="color: blue"&gt;}}&amp;quot;&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;lt;ComboBox &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;23&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ComboBox1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;177&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Margin&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;2&amp;quot;  &lt;/span&gt;&lt;span style="color: red"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Left&amp;quot; 
          &lt;/span&gt;&lt;span style="color: red"&gt;IsEditable&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;False&amp;quot;
          &lt;/span&gt;&lt;span style="color: red"&gt;ItemsSource&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Source&lt;/span&gt;&lt;span style="color: blue"&gt;={&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource &lt;/span&gt;&lt;span style="color: red"&gt;CustomerLookup&lt;/span&gt;&lt;span style="color: blue"&gt;}}&amp;quot;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: red"&gt;          DisplayMemberPath&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;LastName&amp;quot;&lt;br /&gt;&lt;span style="color: red"&gt;          SelectedValuePath&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;CustomerID&amp;quot; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;
&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;          &lt;/span&gt;&lt;span style="color: red"&gt;SelectedValue&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;=CustomerID}&amp;quot; 
          &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;&lt;br /&gt;...&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Code-behind:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Class &lt;/span&gt;Window1
    &lt;span style="color: blue"&gt;Private &lt;/span&gt;db &lt;span style="color: blue"&gt;As New &lt;/span&gt;MyDataObjectContext
    &lt;span style="color: blue"&gt;Private &lt;/span&gt;OrderData &lt;span style="color: blue"&gt;As &lt;/span&gt;IEnumerable(&lt;span style="color: blue"&gt;Of &lt;/span&gt;Order)

    &lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;Window1_Loaded(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;sender &lt;span style="color: blue"&gt;As Object&lt;/span&gt;, &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;e &lt;span style="color: blue"&gt;As &lt;/span&gt;System.Windows.RoutedEventArgs) &lt;span style="color: blue"&gt;Handles Me&lt;/span&gt;.Loaded
        &lt;span style="color: green"&gt;'Load all the orders from the database
        &lt;/span&gt;&lt;span style="color: blue"&gt;Me&lt;/span&gt;.OrderData = db.Orders
        &lt;span style="color: green"&gt;'Get the customer lookup list (this is the Combobox ItemsSource)
        &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;customerList = &lt;span style="color: blue"&gt;From &lt;/span&gt;c &lt;span style="color: blue"&gt;In &lt;/span&gt;db.Customers _
                           &lt;span style="color: blue"&gt;Where &lt;/span&gt;c.Orders.Count &amp;gt; 0 _
                           &lt;span style="color: blue"&gt;Order By &lt;/span&gt;c.LastName, c.FirstName

        &lt;span style="color: blue"&gt;Dim &lt;/span&gt;ordersSource = &lt;span style="color: blue"&gt;CType&lt;/span&gt;(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.FindResource(&lt;span style="color: #a31515"&gt;&amp;quot;OrdersSource&amp;quot;&lt;/span&gt;), CollectionViewSource)
        ordersSource.Source = &lt;span style="color: blue"&gt;Me&lt;/span&gt;.OrderData
        &lt;span style="color: blue"&gt;Dim &lt;/span&gt;custSource = &lt;span style="color: blue"&gt;CType&lt;/span&gt;(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.FindResource(&lt;span style="color: #a31515"&gt;&amp;quot;CustomerLookup&amp;quot;&lt;/span&gt;), CollectionViewSource)
        custSource.Source = customerList.ToList()

    &lt;span style="color: blue"&gt;End Sub&lt;br /&gt;...&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Almost all of this code is just to set up the context of this discussion, you can &lt;a href="http://msdn.microsoft.com/en-us/vbasic/dd239277.aspx" target="_blank"&gt;watch this video for details&lt;/a&gt; on building a complete example. Here I’m using CollectionViewSources in the XAML and setting their Source property in code. This technique is handy especially if you are using nested DataTemplates. The important piece to note are the four properties on the Combobox. ItemsSource, DisplayMemberPath, SelectedValue, and SelectedValuePath. To set up your combobox:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Set the ItemsSource to the list of Customers you want to display in the Combobox.&amp;#160; &lt;/li&gt;

  &lt;li&gt;Next set the DisplayMemberPath to the property name on this list that you want to use to display in the list, here I used LastName. &lt;/li&gt;

  &lt;li&gt;Then set the &lt;strong&gt;SelectedValuePath &lt;/strong&gt;to the property name on this list that will be used to populate the foreign key value on the Order. &lt;/li&gt;

  &lt;li&gt;Finally you set the &lt;strong&gt;SelectedValue&lt;/strong&gt; to the property binding on the Order that is foreign key. LINQ to SQL (and DataSets) will happily save your data with this binding in place. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is how you always bind DataTables and it also works well for LINQ to SQL classes. But since LINQ to SQL classes also include the navigation properties (the Orders collection on Customer and the Customer object reference on Order) you can use a different technique by binding directly to the Customer reference. This is the only choice we have with Entity Framework entities in .NET 3.5 SP1. &lt;/p&gt;

&lt;p&gt;What’s unique with Entity Framework is that the associations between other entities use &lt;strong&gt;only &lt;/strong&gt;navigation properties -- so there isn’t a CustomerID foreign key property value on the Order at all. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/DataBindingWPFLookupComboboxValuestoEFEn_F345/image_6.png"&gt;&lt;img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="279" alt="image" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/DataBindingWPFLookupComboboxValuestoEFEn_F345/image_thumb_2.png" width="448" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;What you have to do instead is &lt;strong&gt;bind directly to the Customer &lt;/strong&gt;object reference. The change in the above example is the Combobox binding in XAML:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ComboBox &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;23&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ComboBox1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;177&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Margin&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;2&amp;quot;  &lt;/span&gt;&lt;span style="color: red"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Left&amp;quot; 
          &lt;/span&gt;&lt;span style="color: red"&gt;IsEditable&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;False&amp;quot;
          &lt;/span&gt;&lt;span style="color: red"&gt;ItemsSource&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Source&lt;/span&gt;&lt;span style="color: blue"&gt;={&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource &lt;/span&gt;&lt;span style="color: red"&gt;CustomerLookup&lt;/span&gt;&lt;span style="color: blue"&gt;}}&amp;quot;
&lt;span style="color: red"&gt;          DisplayMemberPath&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;LastName&amp;quot;&lt;/span&gt;          &lt;br /&gt;&lt;/span&gt;&lt;span style="color: red"&gt;          SelectedItem&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;=Customer}&amp;quot; 
          &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;The important pieces in this case are the three properties on the Combobox. ItemsSource, DisplayMemberPath, and &lt;strong&gt;SelectedItem&lt;/strong&gt;. &lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Set the ItemsSource to the list of Customers you want to display in the Combobox -- same as before. &lt;/li&gt;

  &lt;li&gt;Next set the DisplayMemberPath to the property name on this list that you want to use to display in the list, here I used LastName – same as before. &lt;/li&gt;

  &lt;li&gt;Now set the &lt;strong&gt;SelectedItem&lt;/strong&gt; to the property binding on the Order that is the &lt;strong&gt;navigation property to Customer&lt;/strong&gt;. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This will work properly with LINQ to SQL classes and Entity Framework entities but there is one caveat. You need to make sure that you pull the &lt;strong&gt;entire Customer entity &lt;/strong&gt;into in the lookup list &lt;strong&gt;from the same ObjectContext &lt;/strong&gt;you used to query the Orders. This is because the same ObjectContext (DataContext in LINQ to SQL) needs to resolve the entity references between the queries. Entity Framework does this based on the EntityKeys. The neat side effect of this with EF is that you don’t have to pull down the Customers with the Orders query, they will automatically become references when the Customer lookup list is queried through the same context. (See &lt;a href="http://blogs.msdn.com/bethmassi/archive/2008/12/10/master-details-with-entity-framework-explicit-load.aspx" target="_blank"&gt;my post on explicit load for more details&lt;/a&gt; on how to bring down related EF entities when you only make one call.)&lt;/p&gt;

&lt;p&gt;This behavior may be desired in a lot of scenarios but if we do not need to modify the Customer, like in our example, this can be overkill especially if the Customer has a lot of large fields you aren’t using. In the first example we could have only pulled a subset of fields from the Customer table – the only required ones would be the ones used in the data binding, CustomerID and LastName. So with DataTables and LINQ to SQL classes that bind on the values we could have optimized our lookup list query to:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;customerList = &lt;span style="color: blue"&gt;From &lt;/span&gt;c &lt;span style="color: blue"&gt;In &lt;/span&gt;db.Customers _
                   &lt;span style="color: blue"&gt;Where &lt;/span&gt;c.Orders.Count &amp;gt; 0 _
                   &lt;span style="color: blue"&gt;Order By &lt;/span&gt;c.LastName, c.FirstName _
                   &lt;span style="color: blue"&gt;Select &lt;/span&gt;c.CustomerID, c.LastName&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;This &lt;strong&gt;will not work &lt;/strong&gt;if we bind directly to the navigation properties because the customerList is now a list of anonymous types and not a list of Customer entities. So binding to the values gives you greater flexibility with your lookup list queries. Unfortunately in the current version of EF you cannot bind this way but they are planning to enable this in the next version. In .NET 4.0 the EF team will add support for a new type of association called &amp;quot;FK Associations&amp;quot;. &lt;a href="http://blogs.msdn.com/efdesign/archive/2009/03/16/foreign-keys-in-the-entity-framework.aspx" target="_blank"&gt;Read more about that here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And I’m working on the next set of &lt;a href="http://msdn.microsoft.com/en-us/vbasic/bb466226.aspx#wpfdata" target="_blank"&gt;WPF Forms over Data How Do I videos&lt;/a&gt;, this time with Entity Framework, that will hopefully explain how to use EF in practical way by building WPF data applications. Stay tuned!&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9576176" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Article/default.aspx">Article</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Data/default.aspx">Data</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Entity+Framework/default.aspx">Entity Framework</category></item></channel></rss>