<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
    <channel>
        <title>Raffaeu Bermuda Blog</title>
        <link>http://blog.raffaeu.com/Default.aspx</link>
        <description>NET Coder relocated in Bermuda</description>
        <language>en-US</language>
        <copyright>Raffaeu</copyright>
        <managingEditor>raffaeu@raffaeu.com</managingEditor>
        <generator>Subtext Version 2.0.0.43</generator>
        <image><link>http://creativecommons.org/licenses/by/3.0/</link><url>http://creativecommons.org/images/public/somerights20.gif</url><title>Some Rights Reserved</title></image>
        <creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/RaffaeuEnglishBlog" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
            <title>Build enterprise application with WPF, WCF, Entity Framework and Prism. Tutorial 06.</title>
            <category>WCF</category>
            <category>WPF</category>
            <category>Design Pattern</category>
            <category>C#</category>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/oJualqhl4As/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-to-beat-a-dead-horse.aspx</link>
            <description>&lt;h3&gt;Configure your Customer lookup and run it on IIS 7.0&lt;/h3&gt;  &lt;p&gt;In the previous article we saw how to use WCF (a basic approach) and what we should keep in consideration if we want to use SOA as our repository.&lt;/p&gt;  &lt;p&gt;Now we need to:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Change the WCF service to point to a real database &lt;/li&gt;    &lt;li&gt;Test the service &lt;/li&gt;    &lt;li&gt;Build a web site to host our service &lt;/li&gt;    &lt;li&gt;Host the web site on IIS 7.0 &lt;/li&gt;    &lt;li&gt;The the final result &lt;/li&gt; &lt;/ol&gt;  &lt;h3&gt;Change the Customer service to reflect our database.&lt;/h3&gt;  &lt;p&gt;First of all let’s open the ServiceLibrary project and change the ICustomerService interface to reflect this:&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 500px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: [ServiceContract]
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2: &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; ICustomerService {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4:  [OperationContract]
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5:  IList&amp;lt;CustomerDto&amp;gt; GetCustomers();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:  [OperationContract]
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:  IList&amp;lt;CustomerDto&amp;gt; GetFilteredCustomers(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; searchCriteria);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10: }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;For our menu we need two methods. The first one will retrieve all the available customers, in alphabetical order; the second one will filter this results, in order to show us only the customers that match our search criteria.&lt;/p&gt;

&lt;p&gt;The concrete implementation of this contract will consequently change in this way:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 500px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: List&amp;lt;CustomerDto&amp;gt; Customers = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;CustomerDto&amp;gt;();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2: IRepository customerRepository = 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3:    &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Repository(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ADVConnection());&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Of course, in order to declare our Repository we need to add a reference to the DataLayer project in our WCF service. We need also to reference the entity framework .dll “System.data.entity” and we need also to add the &lt;strong&gt;connectionString&lt;/strong&gt; section in the app.config of our WCF service, otherwise when we will instantiate a new database session (&lt;strong&gt;&lt;em&gt;new ADVConnection())&lt;/em&gt;&lt;/strong&gt; the Visual Studio will throw an error “&lt;em&gt;configuration not found … &lt;/em&gt;”&lt;em&gt;. This happens because the WCF is the final layers so you can use in .NET just one config file in the final layer (UI)&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Now, what we want to do, is to populate the list of customer, in our service library, with the customers available in the database. Because our service is a singleton, we will do that when the first user will call the service:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 500px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; CustomerService() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2:     var result = from c &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; customerRepository.GetAll&amp;lt;Customer&amp;gt;() orderby c.FirstName, c.LastName select c;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3:     &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (var customer &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; result) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4:         Customers.Add(
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5:             &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CustomerDto() { 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6:                 Id = customer.CustomerID, 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:                 FullName = customer.FirstName + "&lt;span style="color: #8b0000"&gt; &lt;/span&gt;" + customer.LastName
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:             }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9:         );
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10:     }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 11: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 12: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 13: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Now, this piece of code is pretty easy and ugly. We should use something like &lt;a href="http://automapper.codeplex.com/" target="_blank"&gt;AutoMapper&lt;/a&gt; to populate on fly our DTO but I want to show you  exactly what happens behind the scene. 

  &lt;br /&gt;We takes all the available customers from the database and one by one, we fill up the Dto with the resultset. 

  &lt;br /&gt;A niece solution here would be also to use an extension method and do something like “&lt;em&gt;from c in customers select c.ToDto()&lt;/em&gt;”&lt;em&gt; &lt;/em&gt;that may returns a IList&amp;lt;CustomerDto&amp;gt;. &lt;img src="http://blog.raffaeu.com/Images/emotions/smiley-wink.gif" border="0" alt="Wink" /&gt;&lt;/p&gt;

&lt;p&gt;The two methods will change consequently in this way:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 500px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; IList&amp;lt;CustomerDto&amp;gt; GetCustomers() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2:     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; Customers;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3: }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;And the filtered version will change in this way:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 500px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; IList&amp;lt;CustomerDto&amp;gt; GetFilteredCustomers(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; searchCriteria) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2:  &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; Customers.FindAll(
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3:   &lt;span style="color: #0000ff"&gt;delegate&lt;/span&gt;(CustomerDto c) { 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4:    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; c.FullName.ToLower()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5:     .Contains(searchCriteria.ToLower()); 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6:   }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:  );
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;We just said to the List “&lt;em&gt;Hey, looks inside the items and whether the items lower case contains this word, keep it&lt;/em&gt;”&lt;em&gt;. &lt;/em&gt;Using this approach will allow us to keep clean the in memory list of customers and retrieve only the customers that match the criteria.&lt;/p&gt;

&lt;h3&gt;Test the environment.&lt;/h3&gt;

&lt;p&gt;Now if we press F5 our project will compile but when we will try to call the GetCustomers, we will receive this error:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_F24E/image.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_F24E/image_thumb.png" width="260" height="167" /&gt;&lt;/a&gt;Visual Studio is pretty nasty in this, because whatever you will say in the app.config, it will use a different app.config “on fly” when you test your service. So in the service windows, click on the app.config under the customer service and change it in this way:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_F24E/image_3.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_F24E/image_thumb_3.png" width="260" height="193" /&gt;&lt;/a&gt;By default WCF doesn’t allow to carry out more than  few bytes on our messages, but because we are retrieving a list of 800 entities … we should increase this parameter. &lt;font color="#ff0000"&gt;
    &lt;br /&gt;&lt;strong&gt;Remember that everything has a cost in resources and it is not a good practice to send and receive a lot of megabytes of message content&lt;/strong&gt;. &lt;/font&gt;&lt;font color="#000000"&gt;Consider using &lt;em&gt;pagination&lt;/em&gt; and other tricks.&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;Now we need to expose this service on a web site. Why? Because when we will develop the UI we will add a reference to an host web site service, like &lt;em&gt;&lt;a href="http://raffaeu.com/service/Customer.svc"&gt;http://raffaeu.com/service/Customer.svc&lt;/a&gt;&lt;/em&gt; and not to a dev address like &lt;a href="http://localhost:9080/PrismTutorial"&gt;&lt;em&gt;http://localhost:9080/PrismTutorial&lt;/em&gt;&lt;/a&gt;&lt;em&gt;… &lt;/em&gt;&lt;img src="http://blog.raffaeu.com/Images/emotions/smiley-smile.gif" border="0" alt="Smile" /&gt;&lt;/p&gt;

&lt;h3&gt;Create a host web site and install it on IIS 7.&lt;/h3&gt;

&lt;p&gt;We need to add a new web site application on our solution, but it has to be a WCF Service web site solution, like the picture below:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_F24E/image_4.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_F24E/image_thumb_4.png" width="260" height="175" /&gt;&lt;/a&gt;Delete all the content except the service.svc file and the web.config.&lt;/p&gt;

&lt;p&gt;First add a new reference to our project ServiceLibrary. 
  &lt;br /&gt;Then add the connection string to the web.config file.&lt;/p&gt;

&lt;p&gt;Finally, change the service.svc to customer.svc and change the HTML code in this way:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 500px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="background-color: #ffff00; color: black"&gt;&amp;lt;%@ 
&lt;/span&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2:    ServiceHost Language="C#" 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3:    Debug="true" 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4:    Service="PrismTutorial.ServiceLibrary.CustomerService" 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5: %&amp;gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Cool, now let’s modify the web.config of our WCF web site and we are done.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_F24E/image_5.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_F24E/image_thumb_5.png" width="260" height="178" /&gt;&lt;/a&gt;I just said to the new endpoint to point to our .dll service library and to expose the contract IServiceContract. The same step we did previously to the service library layer.&lt;/p&gt;

&lt;p&gt;If you now press F5 you can see the process running under ASP.NET. Of course we need to install it on IIS in order to have a common address for our future services. Because the web site points to our project, every time we will change the WCF library this will automatically change in the web service. Of course when we will create new contracts we will need to define new &lt;strong&gt;endpoint &lt;/strong&gt;in both layers.&lt;/p&gt;

&lt;blockquote style="border-bottom: black 1px dashed; border-left: black 1px dashed; padding-bottom: 5px; background-color: #f4f4f4; margin: 5px; padding-left: 5px; padding-right: 5px; border-top: black 1px dashed; border-right: black 1px dashed; padding-top: 5px"&gt;
  &lt;p&gt;Note: if you have, like me, Windows 7 and you want to follow this step, you need to install and configure IIS 7 and WCF for IIS. You can do that by following &lt;a href="http://gasparnagy.blogspot.com/2009/01/enable-wcf-hosing-in-iis-7.html" target="_blank"&gt;this simple and useful post&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Open IIS 7 and install the new application by &lt;strong&gt;creating a new application&lt;/strong&gt; that will point to our project:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_F24E/image_6.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_F24E/image_thumb_6.png" width="260" height="186" /&gt;&lt;/a&gt; If everything is ok, you will be able to browse the folder of this web.app, click on the .svc file, and select &lt;strong&gt;Browse&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You should get this result:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_F24E/image_7.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_F24E/image_thumb_7.png" width="260" height="163" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt; Considerations.&lt;/h3&gt;

&lt;p&gt;This tutorial shows how to create and host a WCF service using Visual Studio and IIS 7. Starting from the next tutorial I will not show you anymore this part as you can use this article as a reference. &lt;/p&gt;

&lt;p&gt;We will create new services and contracts and we will call them asynchronously inside WPF UI.&lt;/p&gt;

&lt;p&gt;I use this approach to get the data on my applications as I can manage better the points of failure of my applications and keep the code separated and clean. If something change on the customer service I can simply add a new method and all the previous versions of my software will continue to work. If my WCF service crashes I can change the web app to point to a different .dll and everything will continue to work. &lt;/p&gt;

&lt;p&gt;Stay tuned as from the next time we will start to build the UI. We will talk about Prism, regions IoC and more.&lt;/p&gt;

&lt;p&gt;Tags: &lt;a href="http://technorati.com/tag/WCF" rel="tag"&gt;WCF&lt;/a&gt; &lt;a href="http://technorati.com/tag/WPF" rel="tag"&gt;WPF&lt;/a&gt; &lt;a href="http://technorati.com/tag/Prism" rel="tag"&gt;Prism&lt;/a&gt; &lt;a href="http://technorati.com/tag/Composite application" rel="tag"&gt;Composite application&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blog.raffaeu.com/aggbug/89.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=oJualqhl4As:4hpSba1nL3s:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=oJualqhl4As:4hpSba1nL3s:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=oJualqhl4As:4hpSba1nL3s:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=oJualqhl4As:4hpSba1nL3s:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=oJualqhl4As:4hpSba1nL3s:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=oJualqhl4As:4hpSba1nL3s:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=oJualqhl4As:4hpSba1nL3s:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=oJualqhl4As:4hpSba1nL3s:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/oJualqhl4As" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/11/08/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-to-beat-a-dead-horse.aspx</guid>
            <pubDate>Sun, 08 Nov 2009 21:13:00 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/89.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/11/08/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-to-beat-a-dead-horse.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/89.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/89.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/11/08/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-to-beat-a-dead-horse.aspx</feedburner:origLink></item>
        <item>
            <title>Build enterprise application with WPF, WCF, Entity Framework and Prism. Tutorial 05.</title>
            <category>C#</category>
            <category>Design Pattern</category>
            <category>WCF</category>
            <category>WPF</category>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/9qYeJIFiKtA/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-once-more.aspx</link>
            <description>&lt;blockquote style="border-bottom: black 1px solid; border-left: black 1px solid; padding-bottom: 5px; background-color: #ffff00; margin: 5px; padding-left: 5px; padding-right: 5px; border-top: black 1px solid; border-right: black 1px solid; padding-top: 5px"&gt;   &lt;p&gt;&lt;strong style="color: #ff0000"&gt;Update: &lt;/strong&gt;source code and documentation are now available on &lt;a href="http://www.codeplex.com" target="_blank"&gt;CodePlex&lt;/a&gt; at this address: &lt;a title="http://prismtutorial.codeplex.com/" href="http://prismtutorial.codeplex.com/"&gt;http://prismtutorial.codeplex.com/&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;Starting with WCF.&lt;/h3&gt;  &lt;p&gt;Today we will see how WCF works and what are the best practices we should use in order to keep our application safe and maintainable.&lt;/p&gt;  &lt;h3&gt;WCF startup.&lt;/h3&gt;  &lt;p&gt;I assume that you know already what is WCF and what’s the difference between WCF and the old Web Service technology. If you don’t, &lt;a href="http://msdn.microsoft.com/en-us/netframework/dd939784.aspx" target="_blank"&gt;this is a nice overview of WCF&lt;/a&gt;, and &lt;a href="http://www.techbubbles.com/wcf/wcf-vs-aspnet-web-services/" target="_blank"&gt;this is a nice overview&lt;/a&gt; of the differences from these 2 technologies.&lt;/p&gt;  &lt;p&gt;The big difference from using a normal data access layer and a SOA service is in the architecture. We must keep in consideration, &lt;strong&gt;always&lt;/strong&gt;, that we are working with a &lt;em&gt;message service&lt;strong&gt; &lt;/strong&gt;&lt;/em&gt;and that all the information are serialized and passed through the network. This point it’s really important because the most common error I saw using WCF is to &lt;strong&gt;serialize&lt;/strong&gt; directly the entities in the domain model … &lt;/p&gt;  &lt;p&gt;Let’s keep as an example our Customer entity.&lt;/p&gt; &lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_A9BF/image.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_A9BF/image_thumb.png" width="260" height="234" /&gt;&lt;/a&gt;   &lt;p&gt;We have a lot of information in this graph and I am pretty sure that we will use those information only when we will look at the details of each customer, so it completely doesn’t make any sense to carry all these information with us for all the time.&lt;/p&gt;  &lt;p&gt;Let’s have a break and let’s see what will be the final result of our application using a sketch. (&lt;em&gt;I use Microsoft &lt;a href="http://www.microsoft.com/expression/products/Blend_Overview.aspx" target="_blank"&gt;Expression Blend sketch available for trial here&lt;/a&gt;&lt;/em&gt;). The style is modified by me to reflect Balsamiq, another Sketch flow design software.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_A9BF/myImage.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="myImage" border="0" alt="myImage" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_A9BF/myImage_thumb.png" width="260" height="197" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;What we will do, when the navigation bar will be open to the &lt;strong&gt;Customer &lt;/strong&gt;section, we will load a list of Customers, but we need only the &lt;strong&gt;Id &lt;/strong&gt;and a &lt;strong&gt;FullName&lt;/strong&gt; that will represent the customer. Then if the user will click on a customer, we will load an additional view with all the details. To accomplish this &lt;strong&gt;data transformation&lt;/strong&gt; we will use a Dto (Data transfer object) &lt;/p&gt;  &lt;blockquote style="border-bottom: gray 1px dashed; border-left: gray 1px solid; padding-bottom: 5px; background-color: #f4f4f4; margin: 5px; padding-left: 5px; padding-right: 5px; border-top: gray 1px solid; border-right: gray 1px solid; padding-top: 5px"&gt;   &lt;p&gt;&lt;i&gt;“The Data Transfer Object "DTO", is a simple serializable object used to transfer data across multiple layers of an application. The fields contained in the DTO are usually primitive types such as strings, boolean, etc. Other DTOs may be contained or aggregated in the DTO.” &lt;/i&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;directly inside WCF. In this way we will have a light version of our customer entity that will be carried over the network.&lt;/p&gt;  &lt;h4&gt;Customer Dto.&lt;/h4&gt;  &lt;p&gt;Let’s create a new WCF project in our solution and add a new class. The class will be a &lt;strong&gt;serialized light version&lt;/strong&gt; of our Customer entity.&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 500px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Runtime.Serialization;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3: &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; PrismTutorial.WCF {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5:     [DataContract]
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; CustomerDto {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:         [DataMember]
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Id { &lt;span style="color: #0000ff"&gt;get&lt;/span&gt;; &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;; }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9:         [DataMember]
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; FullName { &lt;span style="color: #0000ff"&gt;get&lt;/span&gt;; &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;; }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 11:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 12: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 13: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;First of all, the &lt;strong&gt;DataContract attribute&lt;/strong&gt;. This attribute identifies the entity CustomerDto as &lt;strong&gt;serializable&lt;/strong&gt;. Through the attribute &lt;strong&gt;DataMember&lt;/strong&gt; we are saying that both the Id and the FullName properties will be serialized.&lt;/p&gt;

&lt;p&gt;In order to use this Dto, we need a service &lt;strong&gt;contract&lt;/strong&gt; that will allows us to do some simple operations with the Dto. The service contract will expose the operations that we will allow to the end user. &lt;/p&gt;

&lt;p&gt;Let’s add a new interface on our WCF project that will look in this way:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 500px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.ServiceModel;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4: &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; PrismTutorial.WCF {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6:     [ServiceContract]
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:     &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; ICustomerService {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:     
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9:         [OperationContract]
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10:         &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AddCustomer(CustomerDto customer);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 11:         
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 12:         [OperationContract]
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 13:         &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; DeleteCustomer(CustomerDto customer);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 14:         
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 15:         [OperationContract]
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 16:         IList&amp;lt;CustomerDto&amp;gt; GetCustomers();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 17:     
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 18:     }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 19: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 20: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The two attributes that we use now are &lt;strong&gt;ServiceContract&lt;/strong&gt; and &lt;strong&gt;OperationContract&lt;/strong&gt;. The first one will identify the Interface as a WCF contract. Using this attribute we are going to say to WCF: “Hey this is the contract that I want to expose, so let’s look inside and see if there is anything useful for you”.&lt;/p&gt;

&lt;p&gt;The second attribute is identifying our method as visible to the contract. Of course we can have also some methods that we want to include in the service but that we don’t want to expose to the public.&lt;/p&gt;

&lt;p&gt;After that we need to implement in a concrete class our contract and implement the operations. This is just an example so we will have an internal IList of Dto and we will use the operations just to interact with the list exposed by the service.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 500px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Linq;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Web;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.ServiceModel;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7: &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; PrismTutorial.WCF {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:     [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; CustomerService : ICustomerService {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 11:         IList&amp;lt;CustomerDto&amp;gt; Customers = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;CustomerDto&amp;gt;();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 12: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 13:         #region ICustomerService Members
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 14: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 15:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AddCustomer(CustomerDto customer) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 16:             Customers.Add(customer);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 17:         }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 18: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 19:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; DeleteCustomer(CustomerDto customer) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 20:             Customers.Remove(customer);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 21:         }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 22: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 23:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; IList&amp;lt;CustomerDto&amp;gt; GetCustomers() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 24:             &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; Customers;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 25:         }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 26: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 27:         #endregion
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 28:     }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 29: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 30: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The only notable thing here is the attribute &lt;strong&gt;ServiceBehavior &lt;/strong&gt;that explains how our service will be created.  In this case we said that the first call will activate the service, so it’s like using a &lt;strong&gt;&lt;a href="http://www.google.com/url?sa=t&amp;amp;source=web&amp;amp;ct=res&amp;amp;cd=2&amp;amp;ved=0CAsQFjAB&amp;amp;url=http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fms998558.aspx&amp;amp;ei=hs32Sp-qIcqe8Aa7ysHzCQ&amp;amp;usg=AFQjCNH5TTb6DmFWBzA_KX7dGpX7Oaj_YA&amp;amp;sig2=JBZOzgIqf6PMK_vV2Enb8w" target="_blank"&gt;SingleTon&lt;/a&gt; pattern&lt;/strong&gt;. Of course the service behavior attribute has a lot of options.&lt;/p&gt;

&lt;p&gt;We can also use this code in order to be sure that our entity will be correctly removed. Change the intenal IList to a List&amp;lt;T&amp;gt; and change the DeleteCustomer method in this way:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 500px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; DeleteCustomer(CustomerDto customer) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2:    Customers.Remove(Customers.Find(
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3:       c =&amp;gt; c.Id.Equals(customer.Id))
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4:    );
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6: &lt;/pre&gt;&lt;/pre&gt;

&lt;h3&gt;Configure the service.&lt;/h3&gt;

&lt;p&gt;Now that we have our basic service we have to build the solution CTRL+SHIFT+B and then right click on the app.config and select &lt;strong&gt;Configure.&lt;/strong&gt; We will see a window like this one:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_A9BF/image_3.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_A9BF/image_thumb_3.png" width="260" height="193" /&gt;&lt;/a&gt;First of all click on service one and point to the compile .dll in order to have the service to Customer Service and not Service1.&lt;/p&gt;

&lt;p&gt;Now select the endpoint in the service node and again, change it to point to our .dll and select the ICustomerService.&lt;/p&gt;

&lt;p&gt;Now if you press F5 and set the WCF as the startup project, you will be prompt by this windows that is the default test window of Visual Studio 2008 for WCF.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_A9BF/image_4.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_A9BF/image_thumb_4.png" width="260" height="172" /&gt;&lt;/a&gt;By clicking on a method you will be prompted by a default view that allows us to interact with the service in testing mode.&lt;/p&gt;

&lt;p&gt;You can test it by using the addCustomer a couple of times and then the GetCustomers. You will find in the message the customers you previously added.&lt;/p&gt;

&lt;h3&gt;Considerations.&lt;/h3&gt;

&lt;p&gt;In this post we saw how WCF works so now we can do our considerations and create the service for each entity or view, it depends on how you want to structure your software. Of course we should do something better like sending a response message each time we do an operation, or get back the changed list of customers each time we do a CRUD operation. &lt;/p&gt;

&lt;p&gt;The are also other considerations using WCF and attributes that we didn’t see this time. This will be part of the next tutorial.&lt;/p&gt;

&lt;p&gt;Finally, I want to give you some tips using WCF that I have found in the pattern and practices on MSDN web site.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Always consider to use versioning with your data contracts 
    &lt;br /&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/ms733832.aspx" href="http://msdn.microsoft.com/en-us/library/ms733832.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms733832.aspx&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;Version you contract to avoid “breaking changes” 
    &lt;br /&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/ms731060.aspx" href="http://msdn.microsoft.com/en-us/library/ms731060.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms731060.aspx&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;Load balancing with WCF 
    &lt;br /&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/ms730128.aspx" href="http://msdn.microsoft.com/en-us/library/ms730128.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms730128.aspx&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;Mehran Nikoo best practices 
    &lt;br /&gt;&lt;a title="http://mehranikoo.net/CS/archive/2008/05/31/WCF_5F00_Best_5F00_Practices.aspx" href="http://mehranikoo.net/CS/archive/2008/05/31/WCF_5F00_Best_5F00_Practices.aspx"&gt;http://mehranikoo.net/CS/archive/2008/05/31/WCF_5F00_Best_5F00_Practices.aspx&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;Web service software factory for creating robust WCF applications 
    &lt;br /&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/cc487895.aspx" href="http://msdn.microsoft.com/en-us/library/cc487895.aspx"&gt;http://msdn.microsoft.com/en-us/library/cc487895.aspx&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Enjoy this tutorial and stay tuned for the next one!&lt;/p&gt;

&lt;p&gt;Tags: &lt;a href="http://technorati.com/tag/WCF" rel="tag"&gt;WCF&lt;/a&gt; &lt;a href="http://technorati.com/tag/Prism" rel="tag"&gt;Prism&lt;/a&gt; &lt;a href="http://technorati.com/tag/WPF" rel="tag"&gt;WPF&lt;/a&gt; &lt;a href="http://technorati.com/tag/Composite application" rel="tag"&gt;Composite application&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blog.raffaeu.com/aggbug/88.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=9qYeJIFiKtA:qKG_mnz_jVg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=9qYeJIFiKtA:qKG_mnz_jVg:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=9qYeJIFiKtA:qKG_mnz_jVg:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=9qYeJIFiKtA:qKG_mnz_jVg:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=9qYeJIFiKtA:qKG_mnz_jVg:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=9qYeJIFiKtA:qKG_mnz_jVg:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=9qYeJIFiKtA:qKG_mnz_jVg:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=9qYeJIFiKtA:qKG_mnz_jVg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/9qYeJIFiKtA" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/11/08/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-once-more.aspx</guid>
            <pubDate>Sun, 08 Nov 2009 14:24:00 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/88.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/11/08/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-once-more.aspx#feedback</comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/88.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/88.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/11/08/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-once-more.aspx</feedburner:origLink></item>
        <item>
            <title>Build enterprise application with WPF, WCF, Entity Framework and Prism. Tutorial 04.</title>
            <category>WPF</category>
            <category>WCF</category>
            <category>Design Pattern</category>
            <category>C#</category>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/YFCHkPf-lrE/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-and-again.aspx</link>
            <description>&lt;h2&gt;Service Oriented Application.&lt;/h2&gt;  &lt;h3&gt;Introduction.&lt;/h3&gt;  &lt;p&gt;The first problems I always encounter when I design a scalable, multi-tier application are:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Work on a disconnected environment but be able to work with the data previously downloaded.&lt;/li&gt;    &lt;li&gt;Keep always the data up to date, notify the users when the data changes.&lt;/li&gt;    &lt;li&gt;Threading and UI performances, do not provide frozen screen when the user requests the data.&lt;/li&gt;    &lt;li&gt;Synchronization from the database and the disconnected environment.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Those are common problems of a complex software and can be solved using a SOA service solution and WPF for the UI. Of course WPF and WCF by themselves cannot help us without a strong and well designed solution.&lt;/p&gt;  &lt;p&gt;The idea of having a SOA service for the communication will give us the ability to design something like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_DC9B/image.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_DC9B/image_thumb.png" width="260" height="233" /&gt;&lt;/a&gt;  &lt;/p&gt;  &lt;p&gt;Where we will have 1 or more databases, remotely stored somewhere; a distributed SOA service that will allow our software to operate with the remote data, and maybe to have also some security concerns; the final Client application that will be build using some techniques, in order to use the full power of this kind of solution.&lt;/p&gt;  &lt;p&gt;Of course this sketch is fancy and cool but it doesn’t give us anything more than a .PNG file that we can present to the CTO or to the customer! What you have to do in order to transform the sketch in a real solution, it’s complex and hard.&lt;/p&gt;  &lt;h3&gt;Consideration when working with SOA Services.&lt;/h3&gt;  &lt;p&gt;The first consideration we have to do, if we decide to leave the DAL on a remote web service, and work with a completely disconnected environment, is the &lt;strong&gt;&lt;u&gt;data synchronization&lt;/u&gt;&lt;/strong&gt; and the &lt;strong&gt;&lt;u&gt;data&lt;/u&gt;&lt;/strong&gt; &lt;strong&gt;&lt;u&gt;concurrency&lt;/u&gt;&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;Let’s make a very simple self explanatory workflow.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_DC9B/image_3.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_DC9B/image_thumb_3.png" width="260" height="111" /&gt;&lt;/a&gt;  &lt;/p&gt;  &lt;p&gt;We have the order &lt;strong&gt;10-AED-2020&lt;/strong&gt; and is opened remotely by 3 employees in the same time. Everyone makes a change to the row, and then they all try to save the changes. What will happen? … a mess … &lt;img src="http://blog.raffaeu.com/Images/emotions/smiley-wink.gif" border="0" alt="Wink" /&gt;&lt;/p&gt;  &lt;p&gt;Usually, what I do, is to “&lt;em&gt;virtually&lt;/em&gt;” lock the record so when someone else try to open the row, the UI notifies that the row is already opened by someone else. Then when the “&lt;em&gt;someone else”&lt;/em&gt; save or close the row, we notify the changes to everybody.&lt;/p&gt;  &lt;p&gt;The second problem can be called &lt;strong&gt;&lt;u&gt;routing&lt;/u&gt;&lt;/strong&gt; &lt;strong&gt;&lt;u&gt;messaging&lt;/u&gt;&lt;/strong&gt; &lt;strong&gt;&lt;u&gt;approach&lt;/u&gt;&lt;/strong&gt;.     &lt;br /&gt;Also for this problem I have drawn a simple workflow. (Sorry guys but I love Visio!) &lt;img src="http://blog.raffaeu.com/Images/emotions/smiley-tongue-out.gif" border="0" alt="tongue-out" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_DC9B/image_4.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_DC9B/image_thumb_4.png" width="260" height="218" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The process is described below:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;The Vendor requests for a &lt;strong&gt;new order&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;The &lt;strong&gt;software&lt;/strong&gt; submit the request to the &lt;strong&gt;service&lt;/strong&gt; and &lt;strong&gt;&lt;u&gt;wait&lt;/u&gt;&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;The &lt;strong&gt;service&lt;/strong&gt; creates the order&lt;/li&gt;    &lt;li&gt;The &lt;strong&gt;service&lt;/strong&gt; gives back to the &lt;strong&gt;client&lt;/strong&gt; the new order created&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;As you can see we can have two different type of message: &lt;em&gt;a single way message (the request)&lt;/em&gt; and a &lt;em&gt;request and response&lt;/em&gt; message &lt;em&gt;(create order)&lt;/em&gt;, that has a &lt;strong&gt;delay time&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;Of course there are many others considerations but for now this is enough for what we are going to do.&lt;/p&gt;  &lt;h3&gt;Some interesting articles.&lt;/h3&gt;  &lt;p&gt;Before writing XML or C# code I wish you will have the time to read those articles that I have found really interesting, especially if you had never step into an n-tier application.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/dd569749.aspx#id0430125" target="_blank"&gt;MSDN – Build service oriented app&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc700340.aspx" target="_blank"&gt;The Entity Framework In Layered Architectures&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.designpatternsfor.net/Default.aspx?pid=99" target="_blank"&gt;Patterns for Flexible WCF services&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In the next tutorial we will write the code to exposes our entities through WCF, but of course we will not expose directly them but an “&lt;em&gt;alias”&lt;/em&gt;. I will show the differences from using a DTO or something else.&lt;/p&gt;  &lt;p&gt;Stay tuned!&lt;/p&gt;  &lt;p&gt;Tags: &lt;a href="http://technorati.com/tag/WCF" rel="tag"&gt;WCF&lt;/a&gt; &lt;a href="http://technorati.com/tag/WPF" rel="tag"&gt;WPF&lt;/a&gt; &lt;a href="http://technorati.com/tag/Prism" rel="tag"&gt;Prism&lt;/a&gt; &lt;a href="http://technorati.com/tag/Composite application" rel="tag"&gt;Composite application&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blog.raffaeu.com/aggbug/87.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=YFCHkPf-lrE:xVkPU97yKRg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=YFCHkPf-lrE:xVkPU97yKRg:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=YFCHkPf-lrE:xVkPU97yKRg:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=YFCHkPf-lrE:xVkPU97yKRg:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=YFCHkPf-lrE:xVkPU97yKRg:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=YFCHkPf-lrE:xVkPU97yKRg:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=YFCHkPf-lrE:xVkPU97yKRg:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=YFCHkPf-lrE:xVkPU97yKRg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/YFCHkPf-lrE" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/11/01/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-and-again.aspx</guid>
            <pubDate>Sun, 01 Nov 2009 19:41:00 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/87.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/11/01/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-and-again.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/87.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/87.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/11/01/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-and-again.aspx</feedburner:origLink></item>
        <item>
            <title>Build enterprise application with WPF, WCF, Entity Framework and Prism. Tutorial 03.</title>
            <category>C#</category>
            <category>Design Pattern</category>
            <category>WCF</category>
            <category>WPF</category>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/8YDkr2Jtb28/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-yet-again.aspx</link>
            <description>&lt;blockquote style="border-bottom: black 1px solid; border-left: black 1px solid; padding-bottom: 5px; background-color: #ffff00; margin: 5px; padding-left: 5px; padding-right: 5px; border-top: black 1px solid; border-right: black 1px solid; padding-top: 5px"&gt;   &lt;p&gt;&lt;strong style="color: #ff0000"&gt;Update: &lt;/strong&gt;source code and documentation are now available on &lt;a href="http://www.codeplex.com" target="_blank"&gt;CodePlex&lt;/a&gt; at this address: &lt;a title="http://prismtutorial.codeplex.com/" href="http://prismtutorial.codeplex.com/"&gt;http://prismtutorial.codeplex.com/&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;Value and business validation with Enterprise Library 4.1 and Entity Framework.&lt;/h3&gt;  &lt;p&gt;In this article I will show you how to validate a domain using the enterprise library 4.1 over the Entity Framework.&lt;/p&gt;  &lt;p&gt;First of all I want to talk about the &lt;strong&gt;validation&lt;/strong&gt; and the thousands of implementations you can find over the web. In my opinion there are 2 different types of validation. The &lt;strong&gt;value validation&lt;/strong&gt; and the &lt;strong&gt;business validation&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;What’s the difference? The first, the &lt;strong&gt;value validation&lt;/strong&gt; should validate an entity against it’s value content. For example, the entity order should have a validation of type &lt;strong&gt;NotNull&lt;/strong&gt; inside it’s &lt;strong&gt;Id &lt;/strong&gt;field, or a &lt;strong&gt;LengthValidation&lt;/strong&gt; inside it’s order number, in order to reflect the corresponding field in the database table. In this way we will execute a &lt;strong&gt;value validation&lt;/strong&gt; in our domain model, &lt;strong&gt;before sending the data&lt;/strong&gt; to the Data Access Layer.&lt;/p&gt;  &lt;p&gt;The second validation is the &lt;strong&gt;business validation&lt;/strong&gt; and it can be accomplished with a lot of different ways. The most common is the &lt;strong&gt;hard coded way&lt;/strong&gt; that personally, I don’t really like it. What’s a &lt;strong&gt;business validation&lt;/strong&gt;? Let’s say we have an order entity and we have a rule that says &lt;em&gt;“if the total order is grater than 1,000 $ apply 10% of discount”. &lt;/em&gt;This is a &lt;strong&gt;business rule&lt;/strong&gt; that force our entity to change its value after some &lt;strong&gt;business&lt;/strong&gt; considerations.&lt;/p&gt;  &lt;h3&gt;Available validation framework for NET.&lt;/h3&gt;  &lt;p&gt;I use for my value validation the &lt;a href="http://www.codeplex.com/entlib"&gt;Enterprise Library Validation block&lt;/a&gt; and I have found it really useful. The only problem is that this framework forces you to use the &lt;a href="http://en.wikipedia.org/wiki/Decorator_pattern"&gt;decorator pattern&lt;/a&gt;, so we &lt;strong&gt;hard code&lt;/strong&gt; our entity with the value validation rules. This approach is fine, but only if related to the &lt;strong&gt;values. You can also include the value validation in a separate XML file, and this is the solution we will use later.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Another interesting framework is the &lt;a href="http://www.codeplex.com/ValidationFramework"&gt;Validation Framework project on Codeplex&lt;/a&gt;, that similar to the EL, uses decorator and generics to validate our entities.&lt;/p&gt;  &lt;p&gt;Very powerful but with an high learning curve is the powerful &lt;a href="http://www.springframework.net/doc-1.1-M1/reference/html/validation.html"&gt;SPRING.NET framework&lt;/a&gt;, that inside its application blocks has a space also for the validation. What I really like about SPRING.NET is the fact that you will &lt;strong&gt;not hard code&lt;/strong&gt; anything because the entire validation is in a separate XML file. But remember that the learning curve is pretty complex because SPRING.NET is a full IoC tool, so everything is under the concept of be “Injected”.&lt;/p&gt;  &lt;p&gt;Finally, my friend &lt;a href="http://codeclimber.net.nz" target="_blank"&gt;Simone Chiaretta&lt;/a&gt;, suggested me this open source framework: &lt;a href="http://www.codeplex.com/FluentValidation" target="_blank"&gt;Fluent Validation&lt;/a&gt;, that has a nice procedural implementation:&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 540px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; FluentValidation;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; CustomerValidator: AbstractValidator&amp;lt;Customer&amp;gt; {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4:   &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; CustomerValidator() {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5:     RuleFor(customer =&amp;gt; customer.Surname).NotEmpty();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6:     RuleFor(customer =&amp;gt; customer.Forename).NotEmpty().WithMessage("&lt;span style="color: #8b0000"&gt;Please specify a first name&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:     RuleFor(customer =&amp;gt; customer.Company).NotNull();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:     RuleFor(customer =&amp;gt; customer.Discount).NotEqual(0).When(customer =&amp;gt; customer.HasDiscount);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9:     RuleFor(customer =&amp;gt; customer.Address).Length(20, 250);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10:     RuleFor(customer =&amp;gt; customer.Postcode).Must(BeAValidPostcode).WithMessage("&lt;span style="color: #8b0000"&gt;Please specify a valid postcode&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 11:   }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 12: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 13:   &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; BeAValidPostcode(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; postcode) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 14:     &lt;span style="color: #008000"&gt;// custom postcode validating logic goes here&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 15:   }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 16: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 17: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 18: Customer customer = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Customer();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 19: CustomerValidator validator = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CustomerValidator();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 20: ValidationResult results = validator.Validate(customer);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 21: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 22: &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; validationSucceeded = results.IsValid;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 23: IList&amp;lt;ValidationFailure&amp;gt; failures = results.Errors;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 24: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The only &lt;strong&gt;real&lt;/strong&gt; &lt;strong&gt;business validator&lt;/strong&gt; framework for NET that I know and that I use in production is &lt;strong&gt;IBM iLOG for NET&lt;/strong&gt; a real powerful engine for business validation that keeps separate your domain model from the business rules. It’s cool and probably it needs just 10 articles only in order to describe it, so you can have a look at &lt;a href="http://www.ilog.com/products/rulesnet/index.cfm"&gt;the official web site&lt;/a&gt;. This is a simple screenshot of how it works:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.ilog.com/products/rulesnet/index.cfm" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/OctBuildenterpriseapplicationwithWPFWCF_C11A/image.png" width="260" height="214" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;Enterprise Library Validation with Entity Framework.&lt;/h3&gt;

&lt;p&gt;The first problem we have using this framework is the way we can apply the decorator pattern on it. Why? Because in Visual Studio the EF model is built through a DSL tool called Entity Framework designer. So each time we change the model, our validation decorations are lost through the way …&lt;/p&gt;

&lt;p&gt;So let’s add a reference to the enterprise library validation block in our project and let’s try to understand how we can use them in a productive way.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/OctBuildenterpriseapplicationwithWPFWCF_C11A/image_3.png" rel="lightbox[article]"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/OctBuildenterpriseapplicationwithWPFWCF_C11A/image_thumb.png" width="260" height="223" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The first approach is to overwrite with the &lt;strong&gt;partial attribute&lt;/strong&gt; our domain entity is a way like this one:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 540px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; partial &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Customer {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2:     
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; IsValid { &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; Validate(); } }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5:     &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; Validate() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6:         &lt;span style="color: #008000"&gt;//validation implementation&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:         &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:     }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9: }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;and then validate the entity inside the Validate method. Of course because we cannot use the &lt;strong&gt;partial &lt;/strong&gt;attribute for a property we need to find a different way to grab our &lt;strong&gt;validation attributes&lt;/strong&gt;. From XML?&lt;/p&gt;

&lt;p&gt;Good so first of all we need a basic validation class that will validate every single entity using the generics. This solution is the only affordable because the entity generated with EF inherits already from &lt;strong&gt;EntityObject class&lt;/strong&gt;.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 540px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; EntityValidator&amp;lt;T&amp;gt; {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; Dictionary&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;,&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; ValidationErrors { &lt;span style="color: #0000ff"&gt;get&lt;/span&gt;; &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;; }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; Validate&amp;lt;T&amp;gt;(T entity) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6:         ValidationResults results = Validation.ValidateFromConfiguration&amp;lt;T&amp;gt;(entity);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:         &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (results.IsValid) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:             &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9:         } &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10:             &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (var error &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; results) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 11:                 ValidationErrors.Add(error.Key, error.Message);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 12:             }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 13:             &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 14:         }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 15:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 16: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 17: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 18: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Now we can do the validation in this way from the repository, for example:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 540px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Add&amp;lt;T&amp;gt;(T entity) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2:     ADVConnection context = GetObjectContext();
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3:     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (EntityValidator&amp;lt;T&amp;gt;.Validate(entity)) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4:         context.AddObject(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(T).Name, entity);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5:         &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; result = context.SaveChanges();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6:         ReleaseObjectContextIfNotReused();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:         &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; result;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:     }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9:     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; -1;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 11: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;An then we can handle that &lt;strong&gt;return –1&lt;/strong&gt; in a way that we prefer, maybe we can catch it in the “presenter” and interact with the UI. We just need to keep &lt;em&gt;alive&lt;/em&gt; the validation errors generated by the method &lt;strong&gt;&lt;em&gt;Validate&amp;lt;T&amp;gt;&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;Entity Framework mapping file.&lt;/h3&gt;

&lt;p&gt;The Entity Framework works similar to NHibernate, so for each business object we have a mapping file. If you open the .edmx file with a right click-&amp;gt;open with-&amp;gt; XML editor, you will get an XML representation of your model, similar to this file:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 540px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;EntityType&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Customer"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2:   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3:     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;PropertyRef&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"CustomerID"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4:   &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5:   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Property&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"CustomerID"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"int"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Nullable&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"false"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;StoreGeneratedPattern&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Identity"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6:   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Property&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"NameStyle"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"bit"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Nullable&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"false"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Property&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Title"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"nvarchar"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;MaxLength&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"8"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Property&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"FirstName"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"nvarchar"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Nullable&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"false"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;MaxLength&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"50"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9:   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Property&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"MiddleName"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"nvarchar"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;MaxLength&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"50"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10:   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Property&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"LastName"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"nvarchar"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Nullable&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"false"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;MaxLength&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"50"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 11: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;As you can see, we have already all the rules in place, so we do not need to declare anything. For example, the EF already knows that the &lt;strong&gt;Title field&lt;/strong&gt; should be at most, 8 characters long and can be null. Unfortunately, with the version 3 of EF those rules cannot be connected to the Enterprise Library, easily.&lt;/p&gt;

&lt;h3&gt;How we can handle this in our static validator using generics?&lt;/h3&gt;

&lt;p&gt;Close you Visual Studio solution, and navigate to your &lt;strong&gt;Enterprise Library installation folder&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Open the .exe called &lt;strong&gt;EntLibConfig.exe. The first screenshot you will se is something like this:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/OctBuildenterpriseapplicationwithWPFWCF_C11A/image_4.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/OctBuildenterpriseapplicationwithWPFWCF_C11A/image_thumb_3.png" width="260" height="173" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Click on the file menu and open the app.config file in the layer &lt;strong&gt;PrismTutorial.DataLayer.App.Config&lt;/strong&gt;  and you will load the configuration file inside this tool.&lt;/p&gt;

&lt;p&gt;Now, click on the &lt;strong&gt;root of your application&lt;/strong&gt; and select &lt;u&gt;new validation application block&lt;strong&gt;.&lt;/strong&gt;&lt;/u&gt; The result should something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/OctBuildenterpriseapplicationwithWPFWCF_C11A/image_5.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/OctBuildenterpriseapplicationwithWPFWCF_C11A/image_thumb_4.png" width="256" height="260" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now we can create a Rule, or a Rule Set and then we can load our domain model and associate those rules with every entity.&lt;/p&gt;

&lt;p&gt;In order to load the domain model, choose &lt;strong&gt;new Type&lt;/strong&gt;, in the type window, select the PrismTutorial.DataLayer.DomainModel.dll using this button:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/OctBuildenterpriseapplicationwithWPFWCF_C11A/image_6.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/OctBuildenterpriseapplicationwithWPFWCF_C11A/image_thumb_5.png" width="260" height="93" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;At this point you can use the search filter of this window to load one entity per time. I started with the &lt;strong&gt;Customer &lt;/strong&gt;entity. The final result is this one:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/OctBuildenterpriseapplicationwithWPFWCF_C11A/image_7.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/OctBuildenterpriseapplicationwithWPFWCF_C11A/image_thumb_6.png" width="260" height="69" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Finally, right click on the customer and select &lt;strong&gt;new rule set&lt;/strong&gt; and give it a name. In this rule set we will contain all the rules associated with this entity. 

  &lt;br /&gt;Now, on the ruleset node, choose &lt;strong&gt;select members&lt;/strong&gt; and here it’s the magic!!&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/OctBuildenterpriseapplicationwithWPFWCF_C11A/image_8.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/OctBuildenterpriseapplicationwithWPFWCF_C11A/image_thumb_7.png" width="258" height="260" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Finally, you will have now the node &lt;strong&gt;Customer&lt;/strong&gt; showing for every loaded field, an additional node. From here you can select any field and add a new &lt;strong&gt;validator&lt;/strong&gt;. You can include the message template, the type of validation and so on …&lt;/p&gt;

&lt;p&gt;This is my final result:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/OctBuildenterpriseapplicationwithWPFWCF_C11A/image_9.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/OctBuildenterpriseapplicationwithWPFWCF_C11A/image_thumb_8.png" width="260" height="156" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If you open Visual Studio, you will find the app.config file changed. Of course you &lt;strong&gt;cannot change the app.config file when the solution is open because in my case, I work under source control and the app.config is locked.&lt;/strong&gt;&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 540px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1:   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;configSections&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2:     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;section&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"validation"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationSettings, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3:     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;section&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"dataConfiguration"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4:   &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;configSections&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;And the Customer validation rules.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 540px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1:     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;type&lt;/span&gt; &lt;span style="color: #ff0000"&gt;defaultRuleset&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"CustomerValidation"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;assemblyName&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"PrismTutorial.DataLayer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d5210384f83ebb19"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2:       &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"PrismTutorial.DataLayer.Customer"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3:       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ruleset&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"CustomerValidation"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4:         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;properties&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5:           &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;property&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"CustomerID"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6:           &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;property&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"NameStyle"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:           &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;property&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Title"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:           &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;property&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"FirstName"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9:           &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;property&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"MiddleName"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10:           &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;property&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"LastName"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 11:           &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;property&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Suffix"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 12:           &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;property&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"CompanyName"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 13:             &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;validator&lt;/span&gt; &lt;span style="color: #ff0000"&gt;negated&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"false"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;messageTemplate&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Company name cannot be null."&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 14:               &lt;span style="color: #ff0000"&gt;messageTemplateResourceName&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;""&lt;/span&gt; &lt;span style="color: #ff0000"&gt;messageTemplateResourceType&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;""&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 15:               &lt;span style="color: #ff0000"&gt;tag&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;""&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Microsoft.Practices.EnterpriseLibrary.Validation.Validators.NotNullValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 16:               &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Not Null Validator"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 17:             &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;validator&lt;/span&gt; &lt;span style="color: #ff0000"&gt;lowerBound&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"0"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;lowerBoundType&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Ignore"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;upperBound&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"100"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 18:               &lt;span style="color: #ff0000"&gt;upperBoundType&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Inclusive"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;negated&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"false"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;messageTemplate&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Company Name cannot be long more than 100 characters."&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 19:               &lt;span style="color: #ff0000"&gt;messageTemplateResourceName&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;""&lt;/span&gt; &lt;span style="color: #ff0000"&gt;messageTemplateResourceType&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;""&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 20:               &lt;span style="color: #ff0000"&gt;tag&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;""&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 21:               &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"String Length Validator"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Finally I just want to remember you that you can integrate this editor inside Visual Studio 2008 SP1.&lt;/p&gt;

&lt;p&gt;Note: With Visual Studio 2010 and the Entity Framework 4.0, this problem is going to be deprecated because the EF 4 allows us to build POCO object like in NHibernate, so we can then use the decorator pattern or any other type of validation pattern.&lt;/p&gt;

&lt;p&gt;Tags: &lt;a href="http://technorati.com/tag/Prism" rel="tag"&gt;Prism&lt;/a&gt; &lt;a href="http://technorati.com/tag/WPF" rel="tag"&gt;WPF&lt;/a&gt; &lt;a href="http://technorati.com/tag/WCF" rel="tag"&gt;WCF&lt;/a&gt; &lt;a href="http://technorati.com/tag/Composite application" rel="tag"&gt;Composite application&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blog.raffaeu.com/aggbug/86.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=8YDkr2Jtb28:d0rp5QRXDNA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=8YDkr2Jtb28:d0rp5QRXDNA:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=8YDkr2Jtb28:d0rp5QRXDNA:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=8YDkr2Jtb28:d0rp5QRXDNA:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=8YDkr2Jtb28:d0rp5QRXDNA:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=8YDkr2Jtb28:d0rp5QRXDNA:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=8YDkr2Jtb28:d0rp5QRXDNA:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=8YDkr2Jtb28:d0rp5QRXDNA:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/8YDkr2Jtb28" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/11/01/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-yet-again.aspx</guid>
            <pubDate>Sun, 01 Nov 2009 13:56:00 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/86.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/11/01/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-yet-again.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/86.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/86.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/11/01/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-yet-again.aspx</feedburner:origLink></item>
        <item>
            <title>Book review: Beginning ASP.NET MVC 1.0</title>
            <category>ALT</category>
            <category>C#</category>
            <category>ASP.NET</category>
            <category>NET World</category>
            <category>technical documents</category>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/2POlG6ZMrZI/book-review-beginning-asp.net-mvc-1.0.aspx</link>
            <description>&lt;p&gt;A dear friend of mine, &lt;a href="http://codeclimber.net.nz/" target="_blank"&gt;Simone Chiaretta&lt;/a&gt;, &lt;a href="https://mvp.support.microsoft.com/profile=4CEB87C3-2257-408D-AABB-7956CB3E1349" target="_blank"&gt;ASP.NET MVP&lt;/a&gt; wrote an interesting book about ASP.NET MVC in collaboration with &lt;a href="http://nayyeri.net/"&gt;Keyvan Nayyeri&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://codeclimber.net.nz/"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BookreviewBeginningASP.NETMVC1.0_B45F/image.png" width="148" height="180" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The book is &lt;strong&gt;Beginning ASP.NET MVC 1.0&lt;/strong&gt;, edited by Wrox, available on Amazon.com at &lt;a href="http://www.amazon.com/gp/product/047043399X?ie=UTF8&amp;amp;tag=codec04-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=047043399X" target="_blank"&gt;this address&lt;/a&gt; for the price of 31.49 USD.&lt;/p&gt;  &lt;p&gt;I am going to write a review of this book because, first of all, I know Simone and his professionalism. Second, because I am working now on an ASP.NET MVC project in my company, and this book was really helpful for me, so I am pretty sure that it will be the same for you guys. &lt;/p&gt;  &lt;h3&gt;Summary and structure of the book.&lt;/h3&gt;  &lt;p&gt;The book has 19 chapters plus a couple of appendixes. Each chapter covers a specific argument. At the end of each chapter there is always a section for the exercises and a summary section. The first thing you will like about this book is &lt;strong&gt;&lt;u&gt;the huge amount of sample code!&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;At the end of the book there is the appendix B that contains all the solutions related to each exercise, so you won’t get lost.&lt;/p&gt;  &lt;p&gt;The appendix A has a lot of useful links that you can follow, resources, links, books and more.&lt;/p&gt;  &lt;p&gt;Finally there is the index that is done for a “dev” reader. It’s not a normal index but an index divided by alphabetic order that includes also all those components and “code” that you will find in the book. So you will find, for example, the page that talks about “NHibernate”.&lt;/p&gt;  &lt;h3&gt;Case studies.&lt;/h3&gt;  &lt;p&gt;What I really liked about this book is the 2 case studies that you will find at the end. Simone has created these 2 case studies that will reflect 2 real solutions, one is a blog and the second one is … a surprise. I am not going to tell you everything because you &lt;strong&gt;must &lt;/strong&gt;buy it. &lt;img src="http://blog.raffaeu.com/Images/emotions/smiley-wink.gif" border="0" alt="Wink" /&gt;&lt;/p&gt;  &lt;p&gt;This is something really well done as you will apply all the knowledge you got through the book into 2 real solutions!&lt;/p&gt;  &lt;h3&gt;Chapters.&lt;/h3&gt;  &lt;p&gt;Of course I am not going to describe each chapter, but this is the list of chapters so you can understand why this book is so well done, IMHO:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;MVC pattern &lt;/li&gt;    &lt;li&gt;WebForm VS MVC &lt;/li&gt;    &lt;li&gt;Getting started &lt;/li&gt;    &lt;li&gt;The model &lt;/li&gt;    &lt;li&gt;The controller &lt;/li&gt;    &lt;li&gt;The view &lt;/li&gt;    &lt;li&gt;Routing &lt;/li&gt;    &lt;li&gt;Unite test concepts &lt;/li&gt;    &lt;li&gt;Testing ASP.NET MVC &lt;/li&gt;    &lt;li&gt;Components &lt;/li&gt;    &lt;li&gt;Action filters &lt;/li&gt;    &lt;li&gt;AJAX &lt;/li&gt;    &lt;li&gt;Deployment &lt;/li&gt;    &lt;li&gt;Leveraging ASP.NET WebForm futures &lt;/li&gt;    &lt;li&gt;Authentication and authorization &lt;/li&gt;    &lt;li&gt;Extend ASP.NET MVC &lt;/li&gt;    &lt;li&gt;Migrating from ASP.NET &lt;/li&gt;    &lt;li&gt;Case studies &lt;/li&gt;    &lt;li&gt;Resources &lt;/li&gt;    &lt;li&gt;Exercises solutions &lt;/li&gt; &lt;/ol&gt;  &lt;h3&gt;Final Considerations.&lt;/h3&gt;  &lt;p&gt;I am a NET developer, most of time I develop Silverlight/WPF or WinForm applications. For fun I did a couple of ASP.NET MVC applications in the bank where I was working before, but my knowledge about ASP.NET MVC was relative to those projects.&lt;/p&gt;  &lt;p&gt;Now that I got this book, I was able to read all the aspect of MVC pattern applied to ASP.NET and I feel comfortable to build a real application with this framework.&lt;/p&gt;  &lt;p&gt;I did a real ASP.NET MVC application for the Company where I am working now, and I was able to do everything is less than 1 week, including the use of JQuery and AJAX.&lt;/p&gt;  &lt;p&gt;I am really satisfied of this book and I hope that you will buy it as it is a very nice and well written book that will drive you inside this pretty cool framework.&lt;/p&gt;  &lt;p&gt;Thanks Simone and Keyyvan for your effort!&lt;/p&gt;  &lt;p&gt;Tags: &lt;a href="http://technorati.com/tag/Beginning ASP.NET MVC 1.0" rel="tag"&gt;Beginning ASP.NET MVC 1.0&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blog.raffaeu.com/aggbug/85.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=2POlG6ZMrZI:UZEeQwQG1fE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=2POlG6ZMrZI:UZEeQwQG1fE:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=2POlG6ZMrZI:UZEeQwQG1fE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=2POlG6ZMrZI:UZEeQwQG1fE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=2POlG6ZMrZI:UZEeQwQG1fE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=2POlG6ZMrZI:UZEeQwQG1fE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=2POlG6ZMrZI:UZEeQwQG1fE:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=2POlG6ZMrZI:UZEeQwQG1fE:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/2POlG6ZMrZI" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/10/25/book-review-beginning-asp.net-mvc-1.0.aspx</guid>
            <pubDate>Sun, 25 Oct 2009 15:45:00 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/85.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/10/25/book-review-beginning-asp.net-mvc-1.0.aspx#feedback</comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/85.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/85.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/10/25/book-review-beginning-asp.net-mvc-1.0.aspx</feedburner:origLink></item>
        <item>
            <title>Build enterprise application with WPF, WCF, Entity Framework and Prism. Tutorial 02.</title>
            <category>C#</category>
            <category>Design Pattern</category>
            <category>WCF</category>
            <category>WPF</category>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/vCt-xf2KZe0/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-again.aspx</link>
            <description>&lt;blockquote style="border-bottom: black 1px solid; border-left: black 1px solid; padding-bottom: 5px; background-color: #ffff00; margin: 5px; padding-left: 5px; padding-right: 5px; border-top: black 1px solid; border-right: black 1px solid; padding-top: 5px"&gt;   &lt;p&gt;&lt;strong style="color: #ff0000"&gt;Update: &lt;/strong&gt;source code and documentation are now available on &lt;a href="http://www.codeplex.com" target="_blank"&gt;CodePlex&lt;/a&gt; at this address: &lt;a title="http://prismtutorial.codeplex.com/" href="http://prismtutorial.codeplex.com/"&gt;http://prismtutorial.codeplex.com/&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;Build a generic repository with the Entity Framework.&lt;/h2&gt;  &lt;p&gt;In the previous series of articles about M-V-VM we used the AdventureWorks database, available on CodePlex.    &lt;br /&gt;After this article (&lt;a href="http://blog.raffaeu.com/archive/2009/06/05/wpf-and-vmmv-tutorial-02-the-model.aspx" target="_blank"&gt;configure a data layer with LinQ-to-SQL&lt;/a&gt;) I have got some reader’s emails asking me this and that. So, I am going to give you all those answers right now.&lt;/p&gt;  &lt;h3&gt;Download and configure the Adventure Works database.&lt;/h3&gt;  &lt;p&gt;On my dev PC I have SQL Server 2008 Standard version, but this tutorial is working also with the express or any other version.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Go to &lt;a href="http://msftdbprodsamples.codeplex.com/" target="_blank"&gt;CodePlex Adventure Works&lt;/a&gt; web site project and download the AW available version (light and full). I have downloaded the package called &lt;strong&gt;&lt;em&gt;”Adventure Works All Databases”.&lt;/em&gt;&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Go into the folder tree &lt;strong&gt;&lt;em&gt;Tools/Samples&lt;/em&gt;&lt;/strong&gt; and you will find the .mdf and .ldf and also the T-SQL script if you want to run it from a prompt command line. &lt;/li&gt;    &lt;li&gt;Open your SSMS and from the &lt;strong&gt;&lt;em&gt;master&lt;/em&gt;&lt;/strong&gt; database, install the version that you prefer. My samples work with both version, as I use always the Adventure Works LT (Light version). &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_9E03/image.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_9E03/image_thumb.png" width="260" height="185" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;&lt;em&gt;Mandatory: &lt;/em&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font color="#000000"&gt;as I use Windows Authentication in all my samples, you must fix that in your local Db and change the connection string in my samples.&lt;/font&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;h3&gt;Open Visual Studio and create the folder three.&lt;/h3&gt;  &lt;p&gt;As we are going to work with an enterprise application, in order to simulate the 3 tiers, I have created 3 &lt;em&gt;&lt;strong&gt;solution folders&lt;/strong&gt;, &lt;/em&gt;one for the data service, one for the client part and one for the test. We will expand these folders during the building process.&lt;/p&gt;  &lt;p&gt;The initial solution three will be:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_9E03/image_3.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_9E03/image_thumb_3.png" width="260" height="190" /&gt;&lt;/a&gt;&lt;strong&gt;&lt;em&gt;Solution name: &lt;/em&gt;&lt;/strong&gt;PrismTutorial     &lt;br /&gt;&lt;strong&gt;&lt;em&gt;DataLayer: &lt;/em&gt;&lt;/strong&gt;PrismTutorial.DataLayer     &lt;br /&gt;&lt;strong&gt;&lt;em&gt;  TDD: &lt;/em&gt;&lt;/strong&gt;Test.DataLayer     &lt;br /&gt;&lt;strong&gt;&lt;em&gt;Consuming Service: &lt;/em&gt;&lt;/strong&gt;PrismTutorial.WCF &lt;/p&gt;  &lt;h3&gt;Working with Entity Framework.&lt;/h3&gt;  &lt;p&gt;In the first series of tutorials, we used LinQ-to-SQL because:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;It’s easier, It’s faster, It uses the relation 1 to 1 with the database tables and so on. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;For this tutorial we are going to use the Entity Framework because this one is the real OR/M coming from Microsoft so in an enterprise application it’s better to spend more time and effort on building something stronger and reusable.&lt;/p&gt;  &lt;p&gt;Open you VS data layer solution, right click and add an new component, &lt;strong&gt;&lt;em&gt;ADO.NET Entity Data Model&lt;/em&gt;&lt;/strong&gt; and configure it to reflect the Adventure Works LT database installed into your machine.&lt;/p&gt;  &lt;p&gt;After that VS will show up a &lt;strong&gt;&lt;em&gt;entity model designer&lt;/em&gt;&lt;/strong&gt; window very similar to the one that we used with Linq-to-SQL.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_9E03/image_4.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_9E03/image_thumb_4.png" width="260" height="142" /&gt;&lt;/a&gt;If you want to be compliant with my settings, this is how I have configured my Entity Framework:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_9E03/image_5.png" rel="lightbox[tutorial]"&gt;&lt;font color="#333333" /&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_9E03/image_thumb_5.png" width="260" height="193" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;It’s time to play, the Entity Framework repository wrap!&lt;/h3&gt;  &lt;p&gt;Like any software architect, I try to fit always everything in a more generic, reusable and more readable pattern. If we want to have a reusable &lt;strong&gt;&lt;em&gt;UnitOfWork&lt;/em&gt;&lt;/strong&gt; associated with a &lt;strong&gt;&lt;em&gt;Repository&lt;/em&gt;&lt;/strong&gt; engine, we must wrap the Entity Framework inside something more generics. Here comes the pain ….&lt;/p&gt;  &lt;p&gt;The final result I would like to have is this one:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_9E03/image_6.png" rel="lightbox[tutorial]"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_9E03/image_thumb_6.png" width="236" height="260" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h4&gt;IRepository interface.&lt;/h4&gt;  &lt;p&gt;First of all we have to define a generic contract (interface) that we will use as our repository. As we want to be &lt;strong&gt;&lt;em&gt;generic&lt;/em&gt;&lt;/strong&gt; we need something like this:&lt;/p&gt;  &lt;pre style="border-bottom: #004080 1px solid; border-left: #004080 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #004080 1px solid; border-right: #004080 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  2: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  3: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Linq.Expressions;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  4: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  5: &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; PrismTutorial.DataLayer {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  6:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IRepository:IDisposable {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  7:         &lt;span style="color: #008000"&gt;//Add a new Entity&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  8:         &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Add&amp;lt;T&amp;gt;(T entity);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  9:         &lt;span style="color: #008000"&gt;//Count the number of entities available&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 10:         &lt;span style="color: #0000ff"&gt;long&lt;/span&gt; Count&amp;lt;T&amp;gt;();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 11:         &lt;span style="color: #008000"&gt;//Count using a filer&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 12:         &lt;span style="color: #0000ff"&gt;long&lt;/span&gt; Count&amp;lt;T&amp;gt;(Expression&amp;lt;Func&amp;lt;T, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt; expression);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 13:         &lt;span style="color: #008000"&gt;//Delete an existing entity&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 14:         &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Delete&amp;lt;T&amp;gt;(T entity);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 15:         &lt;span style="color: #008000"&gt;//List all the available entities&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 16:         IList&amp;lt;T&amp;gt; GetAll&amp;lt;T&amp;gt;();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 17:         &lt;span style="color: #008000"&gt;//List the entities using a filter&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 18:         IList&amp;lt;T&amp;gt; GetAll&amp;lt;T&amp;gt;(Expression&amp;lt;Func&amp;lt;T, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt; expression);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 19:         &lt;span style="color: #008000"&gt;//Get a single entity&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 20:         T GetSingle&amp;lt;T&amp;gt;(Expression&amp;lt;Func&amp;lt;T,&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt; expression);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 21:         &lt;span style="color: #008000"&gt;//Update an existing entity&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 22:         &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Update&amp;lt;T&amp;gt;(T entity);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 23:     }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 24: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 25: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;At this point we have a generic implementation of the repository pattern and we do not need to worry about what we are going to save, update or delete.&lt;/p&gt;

&lt;h4&gt;BaseRepository to handle the dispose of the data context.&lt;/h4&gt;

&lt;p&gt;The second problem that we have to fix is more related to how the entity framework uses the &lt;strong&gt;&lt;em&gt;context&lt;/em&gt;&lt;/strong&gt; in a web application. I have found this article over the web: &lt;a title="http://blog.zoolutions.se/post/2009/03/26/Generic-Repository-for-Entity-Framework.aspx" href="http://blog.zoolutions.se/post/2009/03/26/Generic-Repository-for-Entity-Framework.aspx"&gt;http://blog.zoolutions.se/post/2009/03/26/Generic-Repository-for-Entity-Framework.aspx&lt;/a&gt;, really interesting, so I am going to use the same type of solution.&lt;/p&gt;

&lt;p&gt;We need a simple base class that is going to handle the data context and close it if not needed. We can also use the &lt;strong&gt;&lt;em&gt;using clause&lt;/em&gt;&lt;/strong&gt; in each method of our repository. I want to use this solution just because it’s more clean and doesn’t force me to write too much code inside the final repository.&lt;/p&gt;

&lt;pre style="border-bottom: #004080 1px solid; border-left: #004080 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #004080 1px solid; border-right: #004080 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  2: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  3: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Linq;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  4: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Text;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  5: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  6: &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; PrismTutorial.DataLayer {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  7:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; BaseRepository {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  8:         &lt;span style="color: #008000"&gt;//Our entity framework engine used in the solution&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  9:         &lt;span style="color: #0000ff"&gt;internal&lt;/span&gt; ADVConnection _context;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 10:         &lt;span style="color: #008000"&gt;//Switch that tells us if the datacontext is reused&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 11:         &lt;span style="color: #0000ff"&gt;internal&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; _contextReused;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 12:         
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 13:         &lt;span style="color: #008000"&gt;//This return the current, or a new connection through the EF&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 14:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ADVConnection GetObjectContext() {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 15:             &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!_contextReused) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 16:                 &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ADVConnection();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 17:             }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 18:             &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _context;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 19:         }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 20: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 21:         &lt;span style="color: #008000"&gt;//This is the public method that we will call from our repository&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 22:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ReleaseObjectContextIfNotReused() {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 23:             &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!_contextReused) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 24:                 ReleaseObjectContext();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 25:             }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 26:         }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 27: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 28:         &lt;span style="color: #008000"&gt;//Simple dispose of the current EF&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 29:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ReleaseObjectContext() {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 30:             &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_context != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 31:                 _context.Dispose();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 32:             }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 33:             _contextReused = &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 34:         }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 35:     }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 36: }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Cool, we just need now to wrap all together and play with the data.&lt;/p&gt;

&lt;h4&gt;The concrete repository.&lt;/h4&gt;

&lt;p&gt;For the repository pattern there are two implementations, one is to keep everything generic and have 1 repository for the entire domain. The second one is to have a repository for each entity, like UserRepository, ProductRepository, and implement the CRUD operations related to the entity, like AddUser, AddProduct and so on.&lt;/p&gt;

&lt;p&gt;I would suggest the second solution only if you need to include some &lt;strong&gt;&lt;em&gt;business logic&lt;/em&gt;&lt;/strong&gt; in your CRUD operations or there are some special development requirements. So let’s go for the easier and faster solution, he first one.&lt;/p&gt;

&lt;p&gt;In the constructor of our repository we need to pass an instance of the &lt;strong&gt;&lt;em&gt;UnitOfWork&lt;/em&gt;&lt;/strong&gt; that in our case is the Entity Framework, like we do with the session with NHibernate.&lt;/p&gt;

&lt;pre style="border-bottom: #004080 1px solid; border-left: #004080 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #004080 1px solid; border-right: #004080 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; PrismTutorial.DataLayer {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  2:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Repository:BaseRepository,IRepository {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  3: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  4:         #region Base Implementation
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  5: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  6:         &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; _disposed;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  7:         &lt;span style="color: #008000"&gt;//Here we pass the connection and we flag the contextReused&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  8:         &lt;span style="color: #008000"&gt;//so we can use the repository with the using clause ...&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  9:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Repository(ADVConnection context) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 10:             &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._context = context;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 11:             &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._contextReused = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 12:         }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 13: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 14:         #endregion
&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Then we have also to implement the IDisposable interface in order to clean-up the connection after each call:&lt;/p&gt;

&lt;pre style="border-bottom: #004080 1px solid; border-left: #004080 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #004080 1px solid; border-right: #004080 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  1:         #region Disposable
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  2:         &lt;span style="color: #008000"&gt;//Dispose implementation&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  3:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Dispose() {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  4:             DisposeObject(&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  5:             GC.SuppressFinalize(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  6:         }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  7:         &lt;span style="color: #008000"&gt;//Distructor&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  8:         ~Repository() {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  9:             DisposeObject(&lt;span style="color: #0000ff"&gt;false&lt;/span&gt;);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 10:         }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 11:         &lt;span style="color: #008000"&gt;//Concrete private implementation of the dispose method&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 12:         &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; DisposeObject(&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; disposing) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 13:             &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_disposed) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 14:                 &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 15:             }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 16:             &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (disposing) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 17:                 &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_context != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 18:                     _context.Dispose();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 19:                 }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 20:                 _disposed = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 21:             }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 22:         }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 23:         #endregion&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Now we can go ahead and implement each C.R.U.D. method and reflects the changes in the entity framework.&lt;/p&gt;

&lt;p&gt;The save method is pretty straightforward, we add an object to our context, using it’s &lt;strong&gt;&lt;em&gt;FullTypeName and we persist the changes in the database. &lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre style="border-bottom: #004080 1px solid; border-left: #004080 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #004080 1px solid; border-right: #004080 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  1:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Add&amp;lt;T&amp;gt;(T entity) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  2:             ADVConnection context = GetObjectContext();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  3:             context.AddObject(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(T).Name, entity);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  4:             &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; result = context.SaveChanges();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  5:             ReleaseObjectContextIfNotReused();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  6:             &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; result;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  7:         }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Same for the count methods except that we have to create an &lt;strong&gt;&lt;em&gt;ObjectQuery&lt;/em&gt;&lt;/strong&gt; that it’s nothing more than a translated query using the T object passed as a parameter.&lt;/p&gt;

&lt;pre style="border-bottom: #004080 1px solid; border-left: #004080 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #004080 1px solid; border-right: #004080 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  1:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;long&lt;/span&gt; Count&amp;lt;T&amp;gt;() {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  2:             ADVConnection context = GetObjectContext();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  3:             var query = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ObjectQuery&amp;lt;T&amp;gt;(
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  4:                 &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(T).Name, 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  5:                 context, 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  6:                 MergeOption.NoTracking);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  7:             &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; count = query.Count();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  8:             ReleaseObjectContextIfNotReused();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt;  9:             &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; count;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 10:         }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 11: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 12:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;long&lt;/span&gt; Count&amp;lt;T&amp;gt;(Expression&amp;lt;Func&amp;lt;T, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt; expression) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 13:             ADVConnection context = GetObjectContext();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 14:             var query = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ObjectQuery&amp;lt;T&amp;gt;(
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 15:                 &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(T).Name, 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 16:                 context, 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 17:                 MergeOption.NoTracking)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 18:                 .Where(expression);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 19:             &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; count = query.Count();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 20:             ReleaseObjectContextIfNotReused();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 21:             &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; count;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 22:         }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 11px"&gt; 23: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The only part that you may not know is the parameter &lt;strong&gt;&lt;em&gt;MergeOption &lt;/em&gt;&lt;/strong&gt;used in the objectquery constructor. MergeOption has the following values (from the source of the NET Framework) :&lt;/p&gt;

&lt;pre style="border-bottom: #004080 1px solid; border-left: #004080 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #004080 1px solid; border-right: #004080 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt;  1: &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; System.Data.Objects {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt;  2:     &lt;span style="color: #008000"&gt;// Summary:&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt;  3:     &lt;span style="color: #008000"&gt;//     Specifies how objects being loaded into the object context are merged with&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt;  4:     &lt;span style="color: #008000"&gt;//     objects already in the object context.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt;  5:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;enum&lt;/span&gt; MergeOption {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt;  6:         &lt;span style="color: #008000"&gt;// Summary:&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt;  7:         &lt;span style="color: #008000"&gt;//     Objects that already exist in the object context are not loaded from the&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt;  8:         &lt;span style="color: #008000"&gt;//     persisted store. This is the default behavior for queries or when calling&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt;  9:         &lt;span style="color: #008000"&gt;//     the System.Data.Objects.DataClasses.EntityCollection&amp;lt;TEntity&amp;gt;.Load(System.Data.Objects.MergeOption)&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 10:         &lt;span style="color: #008000"&gt;//     method on an System.Data.Objects.DataClasses.EntityCollection&amp;lt;TEntity&amp;gt;.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 11:         AppendOnly = 0,
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 12:         &lt;span style="color: #008000"&gt;//&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 13:         &lt;span style="color: #008000"&gt;// Summary:&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 14:         &lt;span style="color: #008000"&gt;//     Objects are always loaded from the persisted store. Any property changes&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 15:         &lt;span style="color: #008000"&gt;//     made to objects in the object context are overwritten by the store values.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 16:         OverwriteChanges = 1,
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 17:         &lt;span style="color: #008000"&gt;//&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 18:         &lt;span style="color: #008000"&gt;// Summary:&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 19:         &lt;span style="color: #008000"&gt;//     When an object exists in the object context, it is not loaded from the persisted&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 20:         &lt;span style="color: #008000"&gt;//     store. Any property changes made to objects in the object context are preserved.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 21:         &lt;span style="color: #008000"&gt;//     This is used to force changes to objects in the object context to save successfully&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 22:         &lt;span style="color: #008000"&gt;//     after an System.Data.OptimisticConcurrencyException has occurred. For more&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 23:         &lt;span style="color: #008000"&gt;//     information, see Saving Changes and Managing Concurrency (Entity Framework).&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 24:         PreserveChanges = 2,
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 25:         &lt;span style="color: #008000"&gt;//&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 26:         &lt;span style="color: #008000"&gt;// Summary:&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 27:         &lt;span style="color: #008000"&gt;//     Objects are maintained in a System.Data.EntityState.Detached state and are&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 28:         &lt;span style="color: #008000"&gt;//     not tracked in the System.Data.Objects.ObjectStateManager.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 29:         NoTracking = 3,
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 30:     }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 31: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 8px"&gt; 32: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Then we need to implement the &lt;strong&gt;delete&lt;/strong&gt; command. Because we are working on a &lt;strong&gt;disconnected&lt;/strong&gt; environment, first of all we need to &lt;strong&gt;get &lt;/strong&gt;the original object from the repository. Then, we delete it.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 540px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Delete&amp;lt;T&amp;gt;(T entity) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2:     ADVConnection context = GetObjectContext();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3:     &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; originalItem;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4:     EntityKey key = context.CreateEntityKey(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(T).Name, entity);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5:     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(context.TryGetObjectByKey(key, &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; originalItem)){
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6:         context.DeleteObject(originalItem);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:     &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; result =  context.SaveChanges();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9:     ReleaseObjectContextIfNotReused();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10:     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; result;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 11: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 12: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Now the easy part, GetAll and GetAll using an expression for the criteria.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 540px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; IList&amp;lt;T&amp;gt; GetAll&amp;lt;T&amp;gt;() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2:     ADVConnection context = GetObjectContext();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3:     IList&amp;lt;T&amp;gt; list = context
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4:         .CreateQuery&amp;lt;T&amp;gt;(
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5:         "&lt;span style="color: #8b0000"&gt;[&lt;/span&gt;" + &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(T).Name + "&lt;span style="color: #8b0000"&gt;]&lt;/span&gt;")
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6:         .ToList();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:     ReleaseObjectContextIfNotReused();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; list;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;With the criteria:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 540px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; IList&amp;lt;T&amp;gt; GetAll&amp;lt;T&amp;gt;(Expression&amp;lt;Func&amp;lt;T, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt; expression) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2:     ADVConnection context = GetObjectContext();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3:     IList&amp;lt;T&amp;gt; list = context
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4:         .CreateQuery&amp;lt;T&amp;gt;(
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5:         "&lt;span style="color: #8b0000"&gt;[&lt;/span&gt;" + &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(T).Name + "&lt;span style="color: #8b0000"&gt;]&lt;/span&gt;")
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6:         .Where(expression)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:         .ToList();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:     ReleaseObjectContextIfNotReused();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9:     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; list;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 11: &lt;/pre&gt;&lt;/pre&gt;
Just a little note here. If you watch this piece of code: 

&lt;p&gt;&lt;strong&gt;&lt;em&gt;.CreateQuery&amp;lt;T&amp;gt;( 
      &lt;br /&gt;                "[" + typeof(T).Name + "]") &lt;/em&gt;&lt;/strong&gt;here I am using the CreateQuery method to get an ObjectQuery object using the generics. Unfortunately this method requires the name of the entity, so we use Reflection and get the name with the method typeof.&lt;/p&gt;

&lt;p&gt;The GetSingle method is the same, we just retreive the FirstOrDefault result of our query:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 540px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; T GetSingle&amp;lt;T&amp;gt;(Expression&amp;lt;Func&amp;lt;T, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt; expression) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2:     ADVConnection context = GetObjectContext();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3:     T result = context
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4:         .CreateQuery&amp;lt;T&amp;gt;(
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5:         "&lt;span style="color: #8b0000"&gt;[&lt;/span&gt;" + &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(T).Name + "&lt;span style="color: #8b0000"&gt;]&lt;/span&gt;")
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6:         .Where(expression)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:         .FirstOrDefault();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:     ReleaseObjectContextIfNotReused();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9:     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; result;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 11: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;And finally, the update method that is going to save the changes we did to an entity.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 540px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Update&amp;lt;T&amp;gt;(T entity) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2:     ADVConnection context = GetObjectContext();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3:     &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; originalItem;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4:     EntityKey key = context.CreateEntityKey(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(T).Name, entity);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5:     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(context.TryGetObjectByKey(key, &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; originalItem)){
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6:         context.ApplyPropertyChanges(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(T).Name,entity);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:     &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; result = context.SaveChanges();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9:     ReleaseObjectContextIfNotReused();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10:     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; result;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 11: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 12: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Like we did with the delete method, first of all we need to retrieve the original instance of the entity, then we simply apply the changes we got from the “working” entity, using the method &lt;strong&gt;&lt;em&gt;ApplyPropertyChanges&lt;/em&gt;&lt;/strong&gt; and finally we save everything.&lt;/p&gt;

&lt;h3&gt;Conclusions.&lt;/h3&gt;

&lt;p&gt;In this article we saw how to work with the entity framework and build a repository pattern around it. The next step will be to include &lt;strong&gt;business and value validation&lt;/strong&gt; to our entities. We will use the enterprise library 4.1.&lt;/p&gt;

&lt;p&gt;Stay tuned!&lt;/p&gt;

&lt;p&gt;Tags: &lt;a href="http://technorati.com/tag/WPF" rel="tag"&gt;WPF&lt;/a&gt; &lt;a href="http://technorati.com/tag/Prism" rel="tag"&gt;Prism&lt;/a&gt; &lt;a href="http://technorati.com/tag/Entity Framework" rel="tag"&gt;Entity Framework&lt;/a&gt; &lt;a href="http://technorati.com/tag/WCF" rel="tag"&gt;WCF&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blog.raffaeu.com/aggbug/84.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=vCt-xf2KZe0:VDXhugq4mGc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=vCt-xf2KZe0:VDXhugq4mGc:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=vCt-xf2KZe0:VDXhugq4mGc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=vCt-xf2KZe0:VDXhugq4mGc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=vCt-xf2KZe0:VDXhugq4mGc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=vCt-xf2KZe0:VDXhugq4mGc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=vCt-xf2KZe0:VDXhugq4mGc:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=vCt-xf2KZe0:VDXhugq4mGc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/vCt-xf2KZe0" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/10/25/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-again.aspx</guid>
            <pubDate>Sun, 25 Oct 2009 14:05:00 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/84.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/10/25/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-again.aspx#feedback</comments>
            <slash:comments>5</slash:comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/84.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/84.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/10/25/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-again.aspx</feedburner:origLink></item>
        <item>
            <title>Build enterprise application with WPF, WCF, Entity Framework and Prism. Tutorial 01.</title>
            <category>WPF</category>
            <category>WCF</category>
            <category>Silverlight</category>
            <category>Design Pattern</category>
            <category>C#</category>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/ohnIId6gUj8/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism.aspx</link>
            <description>&lt;blockquote style="border-bottom: black 1px solid; border-left: black 1px solid; padding-bottom: 5px; background-color: #ffff00; margin: 5px; padding-left: 5px; padding-right: 5px; border-top: black 1px solid; border-right: black 1px solid; padding-top: 5px"&gt;   &lt;p&gt;&lt;strong style="color: #ff0000"&gt;Update: &lt;/strong&gt;source code and documentation are now available on &lt;a href="http://www.codeplex.com" target="_blank"&gt;CodePlex&lt;/a&gt; at this address: &lt;a title="http://prismtutorial.codeplex.com/" href="http://prismtutorial.codeplex.com/"&gt;http://prismtutorial.codeplex.com/&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;In these series of articles I will show you how to build an enterprise application using the most recent Microsoft’s technologies like: WPF with PRISM for the UI, Entity Framework for the Data Layer and WCF for the persistence service.&lt;/p&gt;  &lt;h3&gt;Specifications.&lt;/h3&gt;  &lt;p&gt;We will build a 3 tiers application that will spread the responsibility through 3 different machines (virtually because the Visual Studio solution is only one).&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;SQL Server      &lt;br /&gt;It will contain the database and the database objects &lt;/li&gt;    &lt;li&gt;IIS 7      &lt;br /&gt;Data access layer with Entity Framework       &lt;br /&gt;WCF host service for the persistence       &lt;br /&gt;WCF host service for the security access &lt;/li&gt;    &lt;li&gt;PRISM (Composite WPF application)      &lt;br /&gt;This layer will use the PRISM pattern to render a WPF modular application &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;This is the schema of our tiers: &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_E2A0/image.png" rel="lightbox[TUTORIAL]"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/BuildenterpriseapplicationwithWPFWCFEnt_E2A0/image_thumb.png" width="260" height="189" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Prerequisites and Source code.&lt;/h3&gt;  &lt;p&gt;As I did for my previous series of post about &lt;a href="http://blog.raffaeu.com/archive/2009/06/03/wpf-and-vmmv-tutorial-01-introduction.aspx" target="_blank"&gt;MVVM and WPF&lt;/a&gt;, I will share a CodePlex project for anyone of you that want to reuse the project for professional or testing purposes, I will use the Adventure works database available in the CodePlex web site and I will use the PRISM pattern.&lt;/p&gt;  &lt;p&gt;Prerequisites:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/vstudio/default.aspx" target="_blank"&gt;Visual Studio 2008&lt;/a&gt; with SP1 available for &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=83c3a1ec-ed72-4a79-8961-25635db0192b&amp;amp;displaylang=en" target="_blank"&gt;trial on Microsoft web site&lt;/a&gt;. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=ab99342f-5d1a-413d-8319-81da479ab0d7&amp;amp;displaylang=en" target="_blank"&gt;NET 3.5 SP1&lt;/a&gt; available on MSDN. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.microsoft.com/express/sql/download/" target="_blank"&gt;SQL Server 2008&lt;/a&gt; Express Edition. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;As we are going to use some very well known patterns and methodologies, like: Factory pattern, Inversion of Control, POCO objects, Test Driven Development; I suggest to anyone of you to have a look at:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Martin Fowler &lt;a href="http://martinfowler.com/articles.html" target="_blank"&gt;articles and patterns&lt;/a&gt;. &lt;/li&gt;    &lt;li&gt;Gang of Four &lt;a href="http://www.dofactory.com/Patterns/Patterns.aspx" target="_blank"&gt;NET patterns&lt;/a&gt;. &lt;/li&gt;    &lt;li&gt;Composite UI Application for &lt;a href="http://www.codeplex.com/CompositeWPF" target="_blank"&gt;Silverlight and WPF&lt;/a&gt;. &lt;/li&gt;    &lt;li&gt;At least, basic knowledge of &lt;a href="http://msdn.microsoft.com/en-us/library/ms752059.aspx" target="_blank"&gt;XAML syntax&lt;/a&gt; and how &lt;a href="http://windowsclient.net/wpf/" target="_blank"&gt;WPF works&lt;/a&gt;. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Those are part of the patterns and methodologies we will use. It is not mandatory to know them but if you have at least a look, it will be easier to follow the next articles.&lt;/p&gt;  &lt;p&gt;For today it’s enough, be ready with your PC and from the next article we will start to build the database and the Data access layer.&lt;/p&gt;  &lt;p&gt;Tags: &lt;a href="http://technorati.com/tag/WPF PRISM" rel="tag"&gt;WPF PRISM&lt;/a&gt; &lt;a href="http://technorati.com/tag/Entity Framework" rel="tag"&gt;Entity Framework&lt;/a&gt; &lt;a href="http://technorati.com/tag/WCF" rel="tag"&gt;WCF&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blog.raffaeu.com/aggbug/83.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=ohnIId6gUj8:-b5esfMjxLw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=ohnIId6gUj8:-b5esfMjxLw:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=ohnIId6gUj8:-b5esfMjxLw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=ohnIId6gUj8:-b5esfMjxLw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=ohnIId6gUj8:-b5esfMjxLw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=ohnIId6gUj8:-b5esfMjxLw:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=ohnIId6gUj8:-b5esfMjxLw:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=ohnIId6gUj8:-b5esfMjxLw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/ohnIId6gUj8" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/09/20/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism.aspx</guid>
            <pubDate>Sun, 20 Sep 2009 19:29:39 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/83.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/09/20/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism.aspx#feedback</comments>
            <slash:comments>8</slash:comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/83.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/83.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/09/20/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism.aspx</feedburner:origLink></item>
        <item>
            <title>Virtualizing SQL Server, some tips.</title>
            <category>technical documents</category>
            <category>SQL Server</category>
            <category>NET World</category>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/Nh6HaXJVzXg/virtualizing-sql-server-some-tips.aspx</link>
            <description>&lt;p&gt;I just got these considerations about virtualizing SQL Server on VMWare from my Boss and I would like to share them with you.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;General comments on problems encountered and why people not virtualizing SQL&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Storage ( most people just do not have enough spindles to start with and then when people consolidate they use less spindles not more, error in design and understanding of basic i/o principles )&lt;/li&gt;    &lt;li&gt;Queue lengths are a problem so add as many paths to storage as possible.      &lt;br /&gt;Using vmware makes sequential reads look more like random reads due to interleaving of traffic across vm’s&lt;/li&gt;    &lt;li&gt;Ensure all dbs ( data, temp, log etc ) are on separate vmdks or preferably rdms, improves i/o queue throughput&lt;/li&gt;    &lt;li&gt;Memory ( ensure you set min, max reservations per vm to avoid swapping )&lt;/li&gt;    &lt;li&gt;1 database instance per vmhost ( to allowing you to tweak memory / priorities as required )&lt;/li&gt;    &lt;li&gt;Use the latest intel chips, as provide biggest reduction in latencies for vm tasks&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Following a thru 6 results in linear performance until the cpu saturates around 90%. &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;Basically they said VMware is never the bottleneck ...&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Assuming the rules above are followed you should then consider tweaking the following:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Tweak the o/s first to allow large pages and ensure alignment with storage ( gives +6% improvement )&lt;/li&gt;    &lt;li&gt;Turn on sql priority boost in SQL and ensure correct O/S drivers installed in host ( &lt;strong&gt;gives +14% when used with 1.&lt;/strong&gt; )&lt;/li&gt;    &lt;li&gt;Turn on static transmit coalescing in ESX networking ( gives +1%, so they advise don’t bother )&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;They are interesting considerations. Honestly, I know there are some “how to” and some “best practices” when you prepare a SQL environment. Using separate HD for separate files (mdf, ldf), keep system database separate from user database in different disks, split big tables in different location, maintain the indexes and so on … Unfortunately when you reflect this to a Virtual Environment, everything changes.&lt;/p&gt;  &lt;p&gt;I didn’t find yet a good documentation about virtualizing SQL but I just tried to build a Clustered environment with Windows 2008 R2 x64 and SQL 08 x64 SP1 and the Quad Core I used for my experiments was not enough …&lt;/p&gt;  &lt;p&gt;&lt;img src="http://blog.raffaeu.com/Images/emotions/smiley-smile.gif" border="0" alt="Smile" /&gt;&lt;/p&gt;  &lt;p&gt;Tags: &lt;a href="http://technorati.com/tag/SQL server" rel="tag"&gt;SQL server&lt;/a&gt; &lt;a href="http://technorati.com/tag/vmware" rel="tag"&gt;vmware&lt;/a&gt; &lt;a href="http://technorati.com/tag/virtualize sql server" rel="tag"&gt;virtualize sql server&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blog.raffaeu.com/aggbug/82.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=Nh6HaXJVzXg:gWqOXRImQXA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=Nh6HaXJVzXg:gWqOXRImQXA:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=Nh6HaXJVzXg:gWqOXRImQXA:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=Nh6HaXJVzXg:gWqOXRImQXA:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=Nh6HaXJVzXg:gWqOXRImQXA:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=Nh6HaXJVzXg:gWqOXRImQXA:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=Nh6HaXJVzXg:gWqOXRImQXA:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=Nh6HaXJVzXg:gWqOXRImQXA:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/Nh6HaXJVzXg" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/08/26/virtualizing-sql-server-some-tips.aspx</guid>
            <pubDate>Wed, 26 Aug 2009 17:17:00 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/82.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/08/26/virtualizing-sql-server-some-tips.aspx#feedback</comments>
            <slash:comments>5</slash:comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/82.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/82.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/08/26/virtualizing-sql-server-some-tips.aspx</feedburner:origLink></item>
        <item>
            <title>BizTalk 2009, cannot create project.</title>
            <category>technical documents</category>
            <category>BizTalk</category>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/3TB1NRwFB4Q/biztalk-2009-cannot-create-project.aspx</link>
            <description>&lt;p&gt;In the last days we have received an update for Visual Studio 2008 SP1. The update is 365 MB and it’s called the “&lt;u&gt;&lt;strong&gt;Security Update for Microsoft Visual Studio 2008 Service Pack 1 (KB971092)&lt;/strong&gt;&lt;/u&gt;”.&lt;/p&gt;  &lt;p&gt;After you install this update, when you try to create a new project on BizTalk 2009, you receive in the bottom bar, a notification that says “&lt;strong&gt;&lt;u&gt;Unable to create the Project”&lt;/u&gt;&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;The first solution is:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Open BizTalk 2009 DVD &amp;gt; Select Install BizTalk &lt;/li&gt;    &lt;li&gt;Choose the option Repair&lt;/li&gt;    &lt;li&gt;Reboot the server&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;If you are lucky now you are able to work again with BizTalk 09. If you are not lucky (like me … &lt;img src="http://blog.raffaeu.com/Images/emotions/smiley-smile.gif" border="0" alt="Smile" /&gt;) there is an additional step:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;&lt;em&gt;&lt;u&gt;REBOOT!!&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Tags: &lt;a href="http://technorati.com/tag/BizTalk 2009" rel="tag"&gt;BizTalk 2009&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blog.raffaeu.com/aggbug/81.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=3TB1NRwFB4Q:zhPtj_tTDT0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=3TB1NRwFB4Q:zhPtj_tTDT0:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=3TB1NRwFB4Q:zhPtj_tTDT0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=3TB1NRwFB4Q:zhPtj_tTDT0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=3TB1NRwFB4Q:zhPtj_tTDT0:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=3TB1NRwFB4Q:zhPtj_tTDT0:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=3TB1NRwFB4Q:zhPtj_tTDT0:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=3TB1NRwFB4Q:zhPtj_tTDT0:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/3TB1NRwFB4Q" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/08/25/biztalk-2009-cannot-create-project.aspx</guid>
            <pubDate>Tue, 25 Aug 2009 12:46:00 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/81.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/08/25/biztalk-2009-cannot-create-project.aspx#feedback</comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/81.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/81.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/08/25/biztalk-2009-cannot-create-project.aspx</feedburner:origLink></item>
        <item>
            <title>BizTalk 2009 tutorials available.</title>
            <category>C#</category>
            <category>NET World</category>
            <category>WCF</category>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/nWExmxkDSns/biztalk-2009-tutorials-available.aspx</link>
            <description>&lt;p&gt;I am starting to work on a really interesting project where BizTalk and WCF will be the keys.&lt;/p&gt;  &lt;p&gt;I have used in the past WCF and I am not worried about it, I like it and it’s better than the old Web Services. &lt;/p&gt;  &lt;p&gt;Unfortunately I know BizTalk but I still do not master it. Over the network I didn’t find anything really useful but Microsoft has tons of tutorials and how to.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Overview of BizTalk 2009 &lt;a title="http://www.microsoft.com/biztalk/en/us/roadmap.aspx" href="http://www.microsoft.com/biztalk/en/us/roadmap.aspx"&gt;http://www.microsoft.com/biztalk/en/us/roadmap.aspx&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Getting Started &lt;a title="http://msdn.microsoft.com/en-us/library/aa560946%28BTS.10%29.aspx" href="http://msdn.microsoft.com/en-us/library/aa560946%28BTS.10%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/aa560946%28BTS.10%29.aspx&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Step-by-step with some databases (Oracle, Siebel …) &lt;a title="http://msdn.microsoft.com/en-us/library/aa560946%28BTS.10%29.aspx" href="http://msdn.microsoft.com/en-us/library/aa560946%28BTS.10%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/aa560946%28BTS.10%29.aspx&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Common Tasks &lt;a title="http://msdn.microsoft.com/en-us/library/aa548054%28BTS.10%29.aspx" href="http://msdn.microsoft.com/en-us/library/aa548054%28BTS.10%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/aa548054%28BTS.10%29.aspx&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Complete guide to BizTalk 2009 &lt;a title="http://msdn.microsoft.com/en-us/library/aa548004%28BTS.10%29.aspx" href="http://msdn.microsoft.com/en-us/library/aa548004%28BTS.10%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/aa548004%28BTS.10%29.aspx&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Also, if you need to start with WCF and the NET Framework 3.5, here is what I have found over the network:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Overview &lt;a title="http://msdn.microsoft.com/en-us/netframework/aa663324.aspx" href="http://msdn.microsoft.com/en-us/netframework/aa663324.aspx"&gt;http://msdn.microsoft.com/en-us/netframework/aa663324.aspx&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Beginner &lt;a title="http://msdn.microsoft.com/en-us/netframework/dd939784.aspx" href="http://msdn.microsoft.com/en-us/netframework/dd939784.aspx"&gt;http://msdn.microsoft.com/en-us/netframework/dd939784.aspx&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Probably in the next days I will start to evaluate some books about BizTalk 2009 and WCF. If anyone of you want to ask me to evaluate a book about WCF or BizTalk, I would really appreciate. &lt;img src="http://blog.raffaeu.com/Images/emotions/smiley-wink.gif" border="0" alt="Wink" /&gt;&lt;/p&gt;  &lt;p&gt;Stay tuned!&lt;/p&gt;&lt;img src="http://blog.raffaeu.com/aggbug/80.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=nWExmxkDSns:GIQkG0umMK8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=nWExmxkDSns:GIQkG0umMK8:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=nWExmxkDSns:GIQkG0umMK8:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=nWExmxkDSns:GIQkG0umMK8:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=nWExmxkDSns:GIQkG0umMK8:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=nWExmxkDSns:GIQkG0umMK8:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=nWExmxkDSns:GIQkG0umMK8:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=nWExmxkDSns:GIQkG0umMK8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/nWExmxkDSns" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/08/24/biztalk-2009-tutorials-available.aspx</guid>
            <pubDate>Mon, 24 Aug 2009 14:35:00 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/80.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/08/24/biztalk-2009-tutorials-available.aspx#feedback</comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/80.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/80.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/08/24/biztalk-2009-tutorials-available.aspx</feedburner:origLink></item>
    </channel>
</rss>
