<?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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" 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:dc="http://purl.org/dc/elements/1.1/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>DevTalk .Net Blog</title>
    <link>http://devtalk.dk/</link>
    <description>A blog about .net, software development and achitecture, MicroISV's, lifehacks and tools by Joachim Lykke Andersen</description>
    <language>en-us</language>
    <copyright>Joachim Lykke Andersen</copyright>
    <lastBuildDate>Wed, 16 Feb 2011 20:04:14 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.1.7238.742</generator>
    <managingEditor>joachim@tankefuld.dk</managingEditor>
    <webMaster>joachim@tankefuld.dk</webMaster>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/DevtalknetBlog" /><feedburner:info uri="devtalknetblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
      <trackback:ping>http://devtalk.dk/Trackback.aspx?guid=9bb6b898-9550-4f88-8fd0-c814c6d18a20</trackback:ping>
      <pingback:server>http://devtalk.dk/pingback.aspx</pingback:server>
      <pingback:target>http://devtalk.dk/PermaLink,guid,9bb6b898-9550-4f88-8fd0-c814c6d18a20.aspx</pingback:target>
      <dc:creator>Joachim Lykke Andersen</dc:creator>
      <wfw:comment>http://devtalk.dk/CommentView,guid,9bb6b898-9550-4f88-8fd0-c814c6d18a20.aspx</wfw:comment>
      <wfw:commentRss>http://devtalk.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=9bb6b898-9550-4f88-8fd0-c814c6d18a20</wfw:commentRss>
      <slash:comments>7</slash:comments>
      
      <title>Workaround - EF Code First on AppHabour</title>
      <guid isPermaLink="false">http://devtalk.dk/PermaLink,guid,9bb6b898-9550-4f88-8fd0-c814c6d18a20.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevtalknetBlog/~3/AHQCDG82H6E/Workaround+EF+Code+First+On+AppHabour.aspx</link>
      <pubDate>Wed, 16 Feb 2011 20:04:14 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
If you want to put an application on the fabulous &lt;a href="http://appharbor.com/"&gt;AppHabor&lt;/a&gt; that&#xD;
uses Entity Framework Code First CTP5, then you are going to run into a problem.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
The thing is, that Code-First is very helpful, and wants to create the database and&#xD;
the tables for you, that correspond with your model. Thats nice. But the problem is,&#xD;
that with AppHabor, you have an existing empty database, that you can’t recreate with&#xD;
Code First, but on the other hand, its empty.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
So you really want to leave the DB exist, but just create the tables that you need.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
You have various IDatabaseInitializers available:&#xD;
&lt;/p&gt;&#xD;
        &lt;ul&gt;&#xD;
          &lt;li&gt;&#xD;
CreateDatabaseIfNotExists &#xD;
&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
DropCreateDatabaseAlways &#xD;
&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
DropCreateDatabaseIfModelChanges &#xD;
&lt;/li&gt;&#xD;
        &lt;/ul&gt;&#xD;
        &lt;p&gt;&#xD;
But thats not what you need. So we need to create a new IDatabaseInitializer that&#xD;
just creates the tables.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Well, easier said than done, because all the work being done, is pretty baked in,&#xD;
and unaccessible, so its not really possible to create a nice solution from the outside.&#xD;
So while we wait for the EF team to come through and provide us with the needed scenario,&#xD;
I have rolled a nasty little workaround. The solution is currently running on apphabour&#xD;
on: &#xD;
&lt;/p&gt;&#xD;
        &lt;blockquote&gt;&#xD;
          &lt;p&gt;&#xD;
            &lt;a href="http://codefirsttest.apphb.com/"&gt;http://codefirsttest.apphb.com/&lt;/a&gt;&#xD;
          &lt;/p&gt;&#xD;
        &lt;/blockquote&gt;&#xD;
        &lt;p&gt;&#xD;
All you need to do to get it working is&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
1) to get the Nuget package via “Add Library Package Reference” and search for “EFCodeFirst”&#xD;
or "CreateTablesOnly"&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://nuget.org/Packages/Packages/Details/EFCodeFirst-CreateTablesOnly-1-0-0"&gt;http://nuget.org/Packages/Packages/Details/EFCodeFirst-CreateTablesOnly-1-0-0&lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
2) Add the following line an appropriate place in you code, for instance in your application_start&#xD;
method:&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
DbDatabase.SetInitializer(new DontDropDbJustCreateTablesIfModelChanged&amp;lt;YOURCONTEXT&amp;gt;());&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
You can also download the file directly or have a look at the code below: &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://devtalk.dk/content/binary/DontDropDbJustCreateTablesIfModelChanged.rar"&gt;DontDropDbJustCreateTablesIfModelChanged.rar&#xD;
(1,49 KB)&lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;div class="csharpcode"&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Data.Entity;&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Data.Entity.Database;&lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Data.Entity.Design;&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Data.Entity.Infrastructure;&lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Data.Metadata.Edm;&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Data.Objects;&lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Globalization;&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Security.Cryptography;&lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Text;&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Xml;&lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Linq;&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt; &lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;namespace&lt;/span&gt; Devtalk&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;{&lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;public&lt;/span&gt;&#xD;
            &lt;span class="kwrd"&gt;class&lt;/span&gt; DontDropDbJustCreateTablesIfModelChanged&amp;lt;T&amp;gt; &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                        : IDatabaseInitializer&amp;lt;T&amp;gt; &lt;span class="kwrd"&gt;where&lt;/span&gt; T&#xD;
: DbContext&lt;/pre&gt;&#xD;
          &lt;pre&gt;    {&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;private&lt;/span&gt; EdmMetadata _edmMetaData;&lt;/pre&gt;&#xD;
          &lt;pre&gt; &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;public&lt;/span&gt;&#xD;
            &lt;span class="kwrd"&gt;void&lt;/span&gt; InitializeDatabase(T&#xD;
context)&lt;/pre&gt;&#xD;
          &lt;pre&gt;        {&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;            ObjectContext objectContext = &lt;/pre&gt;&#xD;
          &lt;pre&gt;                  ((IObjectContextAdapter)context).ObjectContext;&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt; &lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;string&lt;/span&gt; modelHash = GetModelHash(objectContext);&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
          &lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (CompatibleWithModel(modelHash, context,&#xD;
objectContext)) &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;return&lt;/span&gt;;&lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
          &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;            DeleteExistingTables(objectContext);&lt;/pre&gt;&#xD;
          &lt;pre&gt;            CreateTables(objectContext);&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
          &lt;/pre&gt;&#xD;
          &lt;pre&gt;            SaveModelHashToDatabase(context, modelHash, objectContext);&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;        }&lt;/pre&gt;&#xD;
          &lt;pre&gt; &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;private&lt;/span&gt;&#xD;
            &lt;span class="kwrd"&gt;void&lt;/span&gt; SaveModelHashToDatabase(T&#xD;
context, &lt;span class="kwrd"&gt;string&lt;/span&gt; modelHash, &lt;/pre&gt;&#xD;
          &lt;pre&gt;                                                ObjectContext objectContext)&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;        {&lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (_edmMetaData != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&#xD;
objectContext.Detach(_edmMetaData);&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
          &lt;/pre&gt;&#xD;
          &lt;pre&gt;            _edmMetaData = &lt;span class="kwrd"&gt;new&lt;/span&gt; EdmMetadata();&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;            context.Set&amp;lt;EdmMetadata&amp;gt;().Add(_edmMetaData);&lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
          &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;            _edmMetaData.ModelHash = modelHash;&lt;/pre&gt;&#xD;
          &lt;pre&gt;            context.SaveChanges();&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;        }&lt;/pre&gt;&#xD;
          &lt;pre&gt; &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;private&lt;/span&gt;&#xD;
            &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateTables(ObjectContext&#xD;
objectContext)&lt;/pre&gt;&#xD;
          &lt;pre&gt;        {&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;string&lt;/span&gt; dataBaseCreateScript&#xD;
= &lt;/pre&gt;&#xD;
          &lt;pre&gt;                objectContext.CreateDatabaseScript();&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;            objectContext.ExecuteStoreCommand(dataBaseCreateScript);&lt;/pre&gt;&#xD;
          &lt;pre&gt;        }&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt; &lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;private&lt;/span&gt;&#xD;
            &lt;span class="kwrd"&gt;void&lt;/span&gt; DeleteExistingTables(ObjectContext&#xD;
objectContext)&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;        {&lt;/pre&gt;&#xD;
          &lt;pre&gt;            objectContext.ExecuteStoreCommand(Dropallconstraintsscript);&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;            objectContext.ExecuteStoreCommand(Deletealltablesscript);&lt;/pre&gt;&#xD;
          &lt;pre&gt;        }&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt; &lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;private&lt;/span&gt;&#xD;
            &lt;span class="kwrd"&gt;string&lt;/span&gt; GetModelHash(ObjectContext&#xD;
context)&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;        {&lt;/pre&gt;&#xD;
          &lt;pre&gt;            var csdlXmlString = GetCsdlXmlString(context).ToString();&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;return&lt;/span&gt; ComputeSha256Hash(csdlXmlString);&lt;/pre&gt;&#xD;
          &lt;pre&gt;        }&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt; &lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;private&lt;/span&gt;&#xD;
            &lt;span class="kwrd"&gt;bool&lt;/span&gt; CompatibleWithModel(&lt;span class="kwrd"&gt;string&lt;/span&gt; modelHash,&#xD;
DbContext context, &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                                            ObjectContext objectContext)&lt;/pre&gt;&#xD;
          &lt;pre&gt;        {&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;            var isEdmMetaDataInStore = &lt;/pre&gt;&#xD;
          &lt;pre&gt;                objectContext.ExecuteStoreQuery&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;(LookupEdmMetaDataTable)&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                .FirstOrDefault();&lt;/pre&gt;&#xD;
          &lt;pre&gt; &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (isEdmMetaDataInStore ==&#xD;
1)&lt;/pre&gt;&#xD;
          &lt;pre&gt;            {            &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                _edmMetaData = context.Set&amp;lt;EdmMetadata&amp;gt;().FirstOrDefault();&lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (_edmMetaData != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                {&lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;return&lt;/span&gt; modelHash == _edmMetaData.ModelHash;&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                }&lt;/pre&gt;&#xD;
          &lt;pre&gt;            }&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;return&lt;/span&gt;&#xD;
            &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;/pre&gt;&#xD;
          &lt;pre&gt;        }&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt; &lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;private&lt;/span&gt;&#xD;
            &lt;span class="kwrd"&gt;string&lt;/span&gt; GetCsdlXmlString(ObjectContext&#xD;
context)&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;        {&lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (context != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;            {&lt;/pre&gt;&#xD;
          &lt;pre&gt;                var entityContainerList = context.MetadataWorkspace&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                    .GetItems&amp;lt;EntityContainer&amp;gt;(DataSpace.SSpace);&lt;/pre&gt;&#xD;
          &lt;pre&gt; &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (entityContainerList&#xD;
!= &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;/pre&gt;&#xD;
          &lt;pre&gt;                {&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                    var entityContainer = entityContainerList.FirstOrDefault();&lt;/pre&gt;&#xD;
          &lt;pre&gt;                    var generator = &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;new&lt;/span&gt; EntityModelSchemaGenerator(entityContainer);&lt;/pre&gt;&#xD;
          &lt;pre&gt;                    var stringBuilder = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder();&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                    var xmlWRiter = XmlWriter.Create(stringBuilder);&lt;/pre&gt;&#xD;
          &lt;pre&gt;                    generator.GenerateMetadata();&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                    generator.WriteModelSchema(xmlWRiter);&lt;/pre&gt;&#xD;
          &lt;pre&gt;                    xmlWRiter.Flush();&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;return&lt;/span&gt; stringBuilder.ToString();&lt;/pre&gt;&#xD;
          &lt;pre&gt;                }&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;            }&lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;return&lt;/span&gt;&#xD;
            &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty;&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;        }&lt;/pre&gt;&#xD;
          &lt;pre&gt; &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;private&lt;/span&gt;&#xD;
            &lt;span class="kwrd"&gt;static&lt;/span&gt;&#xD;
            &lt;span class="kwrd"&gt;string&lt;/span&gt; ComputeSha256Hash(&lt;span class="kwrd"&gt;string&lt;/span&gt; input)&lt;/pre&gt;&#xD;
          &lt;pre&gt;        {&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;byte&lt;/span&gt;[] buffer = &lt;span class="kwrd"&gt;new&lt;/span&gt; SHA256Managed()&lt;/pre&gt;&#xD;
          &lt;pre&gt;                .ComputeHash(Encoding.ASCII.GetBytes(input));&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt; &lt;/pre&gt;&#xD;
          &lt;pre&gt;            var builder = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder(buffer.Length&#xD;
* 2);&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;byte&lt;/span&gt; num &lt;span class="kwrd"&gt;in&lt;/span&gt; buffer)&lt;/pre&gt;&#xD;
          &lt;pre&gt;            {&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                builder.Append(num.ToString(&lt;span class="str"&gt;"X2"&lt;/span&gt;, &lt;/pre&gt;&#xD;
          &lt;pre&gt;                    CultureInfo.InvariantCulture));&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;            }&lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;return&lt;/span&gt; builder.ToString();&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;        }&lt;/pre&gt;&#xD;
          &lt;pre&gt; &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;private&lt;/span&gt;&#xD;
            &lt;span class="kwrd"&gt;const&lt;/span&gt;&#xD;
            &lt;span class="kwrd"&gt;string&lt;/span&gt; Dropallconstraintsscript&#xD;
=&lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="str"&gt;@"select &#xD;
&lt;/span&gt;&#xD;
          &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                'ALTER TABLE ' + so.table_name + ' DROP CONSTRAINT ' &lt;/pre&gt;&#xD;
          &lt;pre&gt;                + so.constraint_name  &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                from INFORMATION_SCHEMA.TABLE_CONSTRAINTS so";&lt;/pre&gt;&#xD;
          &lt;pre&gt; &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="kwrd"&gt;private&lt;/span&gt;&#xD;
            &lt;span class="kwrd"&gt;const&lt;/span&gt;&#xD;
            &lt;span class="kwrd"&gt;string&lt;/span&gt; Deletealltablesscript&#xD;
=&lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="str"&gt;@"declare @cmd varchar(4000)&#xD;
&lt;/span&gt;&#xD;
          &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                declare cmds cursor for &lt;/pre&gt;&#xD;
          &lt;pre&gt;                Select&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                    'drop table [' + Table_Name + ']'&lt;/pre&gt;&#xD;
          &lt;pre&gt;                From&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                    INFORMATION_SCHEMA.TABLES&lt;/pre&gt;&#xD;
          &lt;pre&gt; &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                open cmds&lt;/pre&gt;&#xD;
          &lt;pre&gt;                while 1=1&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                begin&lt;/pre&gt;&#xD;
          &lt;pre&gt;                    fetch cmds into @cmd&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                    if @@fetch_status != 0 break&lt;/pre&gt;&#xD;
          &lt;pre&gt;                    print @cmd&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                    exec(@cmd)&lt;/pre&gt;&#xD;
          &lt;pre&gt;                end&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;                close cmds&lt;/pre&gt;&#xD;
          &lt;pre&gt;                deallocate cmds";&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt; &lt;/pre&gt;&#xD;
          &lt;pre&gt;&#xD;
            &lt;span class="kwrd"&gt;private&lt;/span&gt;&#xD;
            &lt;span class="kwrd"&gt;const&lt;/span&gt;&#xD;
            &lt;span class="kwrd"&gt;string&lt;/span&gt; LookupEdmMetaDataTable&#xD;
=&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;&#xD;
            &lt;span class="str"&gt;@"Select COUNT(*) &#xD;
&lt;/span&gt;&#xD;
          &lt;/pre&gt;&#xD;
          &lt;pre&gt;              FROM INFORMATION_SCHEMA.TABLES T &lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;              Where T.TABLE_NAME = 'EdmMetaData'";&lt;/pre&gt;&#xD;
          &lt;pre&gt;    }&lt;/pre&gt;&#xD;
          &lt;pre class="alt"&gt;}&lt;/pre&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;style type="text/css"&gt;&#xD;
&#xD;
.csharpcode, .csharpcode pre&#xD;
{&#xD;
	font-size: small;&#xD;
	color: black;&#xD;
	font-family: consolas, "Courier New", courier, monospace;&#xD;
	background-color: #ffffff;&#xD;
	/*white-space: pre;*/&#xD;
}&#xD;
.csharpcode pre { margin: 0em; }&#xD;
.csharpcode .rem { color: #008000; }&#xD;
.csharpcode .kwrd { color: #0000ff; }&#xD;
.csharpcode .str { color: #006080; }&#xD;
.csharpcode .op { color: #0000c0; }&#xD;
.csharpcode .preproc { color: #cc6633; }&#xD;
.csharpcode .asp { background-color: #ffff00; }&#xD;
.csharpcode .html { color: #800000; }&#xD;
.csharpcode .attr { color: #ff0000; }&#xD;
.csharpcode .alt &#xD;
{&#xD;
	background-color: #f4f4f4;&#xD;
	width: 100%;&#xD;
	margin: 0em;&#xD;
}&#xD;
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&#xD;
        &lt;img width="0" height="0" src="http://devtalk.dk/aggbug.ashx?id=9bb6b898-9550-4f88-8fd0-c814c6d18a20"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=AHQCDG82H6E:uzvVYq-NZWQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=AHQCDG82H6E:uzvVYq-NZWQ:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=AHQCDG82H6E:uzvVYq-NZWQ:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=AHQCDG82H6E:uzvVYq-NZWQ:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=AHQCDG82H6E:uzvVYq-NZWQ:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=AHQCDG82H6E:uzvVYq-NZWQ:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=AHQCDG82H6E:uzvVYq-NZWQ:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=AHQCDG82H6E:uzvVYq-NZWQ:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=AHQCDG82H6E:uzvVYq-NZWQ:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevtalknetBlog/~4/AHQCDG82H6E" height="1" width="1"/&gt;</description>
      <comments>http://devtalk.dk/CommentView,guid,9bb6b898-9550-4f88-8fd0-c814c6d18a20.aspx</comments>
      <category>Code First</category>
      <category>CTP5</category>
      <category>EF4</category>
    <feedburner:origLink>http://devtalk.dk/2011/02/16/Workaround+EF+Code+First+On+AppHabour.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://devtalk.dk/Trackback.aspx?guid=601a116a-4df8-43fd-8da4-7152746144b0</trackback:ping>
      <pingback:server>http://devtalk.dk/pingback.aspx</pingback:server>
      <pingback:target>http://devtalk.dk/PermaLink,guid,601a116a-4df8-43fd-8da4-7152746144b0.aspx</pingback:target>
      <dc:creator>Joachim Lykke Andersen</dc:creator>
      <wfw:comment>http://devtalk.dk/CommentView,guid,601a116a-4df8-43fd-8da4-7152746144b0.aspx</wfw:comment>
      <wfw:commentRss>http://devtalk.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=601a116a-4df8-43fd-8da4-7152746144b0</wfw:commentRss>
      <slash:comments>8</slash:comments>
      
      <title>How to Run T4MVC on Build</title>
      <guid isPermaLink="false">http://devtalk.dk/PermaLink,guid,601a116a-4df8-43fd-8da4-7152746144b0.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevtalknetBlog/~3/mF9_843XOCI/How+To+Run+T4MVC+On+Build.aspx</link>
      <pubDate>Thu, 11 Mar 2010 22:22:58 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://mvccontrib.codeplex.com/wikipage?title=T4MVC"&gt;T4MVC&lt;/a&gt; is a very&#xD;
nifty little T4 template that generates some strongly typed helpers, to avoid fiddling&#xD;
with strings when referring to controllers, actions and views.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Its build using EnvDTE these days, so you don’t have to build your solution before&#xD;
running the template, which is nice.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
There is however one slight little thing, that would make the experience complete:&#xD;
If it would run before build, so its always updated and we thereby avoid build errors&#xD;
due to errors in generated code.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Out of the box, this is nearly working due to the setting AlwaysKeepTemplateDirty,&#xD;
that sets the saved boolean to false, forcing the template to run. But this only works&#xD;
if the template has run once.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
So when you open Visual Studio and change a MVC controller, you have the problem.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
The only way i could figure out how to do this, was to use EnvDTE and add an eventhandler&#xD;
to the BuildEvents.OnBuildBegin event.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
You push ALT+F11 to get to the &lt;code&gt;Macro IDE&lt;/code&gt;, click &lt;code&gt;EnvironmenEvents&lt;/code&gt; and&#xD;
add the eventhandler in the below code snippet . Make sure that its added outside&#xD;
the autogenerated code section.&#xD;
&lt;/p&gt;&#xD;
        &lt;pre class="brush: vb; gutter: false; toolbar: false;"&gt;Public Sub OnBuildBegin(ByVal Scope As EnvDTE.vsBuildScope, _&#xD;
                        ByVal Action As EnvDTE.vsBuildAction) _&#xD;
                        Handles BuildEvents.OnBuildBegin&#xD;
 &#xD;
    If Scope = vsBuildScope.vsBuildScopeSolution _&#xD;
        Or Scope = vsBuildScope.vsBuildScopeProject Then&#xD;
 &#xD;
        Dim projectItem As ProjectItem _&#xD;
            = DTE.Solution.FindProjectItem("T4MVC.tt")&#xD;
 &#xD;
        If Not projectItem Is Nothing Then&#xD;
            If Not projectItem.IsOpen Then&#xD;
                projectItem.Open()&#xD;
            End If&#xD;
            projectItem.Save()&#xD;
        End If&#xD;
 &#xD;
    End If&#xD;
End Sub&lt;/pre&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;***UPDATE***&lt;/strong&gt;: Encouraged by the comment by David Ebbo, I have modified&#xD;
the code a little so that it runs the custom tool directly instead of opening and&#xD;
saving the file. This is cleaner, but you have to reference the VSLangProj.dll, to&#xD;
use the VSProjectItem.&#xD;
&lt;/p&gt;&#xD;
        &lt;pre class="brush: vb; gutter: false; toolbar: false;"&gt;Public Sub OnBuildBegin(ByVal Scope As EnvDTE.vsBuildScope, _&#xD;
                ByVal Action As EnvDTE.vsBuildAction) _&#xD;
                Handles BuildEvents.OnBuildBegin&#xD;
 &#xD;
    If Scope = vsBuildScope.vsBuildScopeSolution _&#xD;
        Or Scope = vsBuildScope.vsBuildScopeProject Then&#xD;
 &#xD;
        Dim projectItem As VSProjectItem _&#xD;
            = DTE.Solution.FindProjectItem("T4MVC.tt").Object&#xD;
 &#xD;
        If Not projectItem Is Nothing Then&#xD;
            projectItem.RunCustomTool()&#xD;
        End If&#xD;
 &#xD;
    End If&#xD;
End Sub&lt;/pre&gt;&#xD;
        &lt;p&gt;&#xD;
This obviously isn’t the perfect solution, as it is run for all solutions or projects&#xD;
that you build – not just MVC ones. But if you keep it while you primarily work on&#xD;
MVC projects with T4MVC, and then comment it out when not, you’ll be fine.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
This could also be wrapped up in an Addin, so that you could turn it on and off via&#xD;
the Addin menu.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Remember to change the filename if you are using &lt;a href="http://www.rorybecker.me.uk/"&gt;Rory&#xD;
Beckers&lt;/a&gt; VB version &lt;a href="http://www.rorybecker.me.uk/Microsoft/T4MVCVB.zip"&gt;T4MVCVB.tt&lt;/a&gt;&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Resources:&#xD;
&lt;/p&gt;&#xD;
        &lt;ul&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://mvccontrib.codeplex.com/wikipage?title=T4MVC"&gt;T4MVC&lt;/a&gt;&#xD;
          &lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://www.rorybecker.me.uk/Microsoft/T4MVCVB.zip"&gt;T4MVCVB&lt;/a&gt;&#xD;
          &lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://stackoverflow.com/questions/2341717/can-you-do-a-runcustomtool-with-envdte-as-a-pre-build-event"&gt;My&#xD;
original answer on Stackoverflow.com&lt;/a&gt;&#xD;
          &lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://blogs.msdn.com/davidebb/archive/tags/T4MVC/default.aspx"&gt;David Ebbo&#xD;
on T4MVC&lt;/a&gt;&#xD;
          &lt;/li&gt;&#xD;
        &lt;/ul&gt;&#xD;
        &lt;img width="0" height="0" src="http://devtalk.dk/aggbug.ashx?id=601a116a-4df8-43fd-8da4-7152746144b0"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=mF9_843XOCI:3V55KA5ki9w:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=mF9_843XOCI:3V55KA5ki9w:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=mF9_843XOCI:3V55KA5ki9w:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=mF9_843XOCI:3V55KA5ki9w:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=mF9_843XOCI:3V55KA5ki9w:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=mF9_843XOCI:3V55KA5ki9w:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=mF9_843XOCI:3V55KA5ki9w:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=mF9_843XOCI:3V55KA5ki9w:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=mF9_843XOCI:3V55KA5ki9w:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevtalknetBlog/~4/mF9_843XOCI" height="1" width="1"/&gt;</description>
      <comments>http://devtalk.dk/CommentView,guid,601a116a-4df8-43fd-8da4-7152746144b0.aspx</comments>
    <feedburner:origLink>http://devtalk.dk/2010/03/11/How+To+Run+T4MVC+On+Build.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://devtalk.dk/Trackback.aspx?guid=f455512e-1fbe-4ea6-ad78-ee3f7c3003df</trackback:ping>
      <pingback:server>http://devtalk.dk/pingback.aspx</pingback:server>
      <pingback:target>http://devtalk.dk/PermaLink,guid,f455512e-1fbe-4ea6-ad78-ee3f7c3003df.aspx</pingback:target>
      <dc:creator>Joachim Lykke Andersen</dc:creator>
      <wfw:comment>http://devtalk.dk/CommentView,guid,f455512e-1fbe-4ea6-ad78-ee3f7c3003df.aspx</wfw:comment>
      <wfw:commentRss>http://devtalk.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=f455512e-1fbe-4ea6-ad78-ee3f7c3003df</wfw:commentRss>
      
      <title>Danish Podcast: Entity Framework 4.0 Beta 1</title>
      <guid isPermaLink="false">http://devtalk.dk/PermaLink,guid,f455512e-1fbe-4ea6-ad78-ee3f7c3003df.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevtalknetBlog/~3/CKeBN6UfPfk/Danish+Podcast+Entity+Framework+40+Beta+1.aspx</link>
      <pubDate>Mon, 03 Aug 2009 18:11:08 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
A while ago I was on &lt;a href="http://feeds.feedburner.com/anugcast"&gt;AnugCast&lt;/a&gt; with &lt;a href="http://publicvoid.dk/"&gt;Søren&#xD;
Spelling Lund&lt;/a&gt; and talked about Entity Framework 4.0, and now its been released.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
We talk about version 1, Vote of no confidence, what happened to version 2 and 3,&#xD;
the road to 4.0, and of course all the new stuff like POCO, Model First, Deferred&#xD;
Load, T4 templates, Persistance ignorance support, Code only etc. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Download: [DK] &lt;a href="http://www.anug.dk/post/2009/08/02/ANUGCast-41-Entity-Framework-40-med-Joachim-Lykke-Andersen.aspx"&gt;ANUGCast&#xD;
#41 Entity Framework 4.0 med Joachim Lykke Andersen&lt;/a&gt;&lt;/p&gt;&#xD;
        &lt;img width="0" height="0" src="http://devtalk.dk/aggbug.ashx?id=f455512e-1fbe-4ea6-ad78-ee3f7c3003df"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=CKeBN6UfPfk:UipAA7a4ADc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=CKeBN6UfPfk:UipAA7a4ADc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=CKeBN6UfPfk:UipAA7a4ADc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=CKeBN6UfPfk:UipAA7a4ADc:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=CKeBN6UfPfk:UipAA7a4ADc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=CKeBN6UfPfk:UipAA7a4ADc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=CKeBN6UfPfk:UipAA7a4ADc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=CKeBN6UfPfk:UipAA7a4ADc:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=CKeBN6UfPfk:UipAA7a4ADc:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevtalknetBlog/~4/CKeBN6UfPfk" height="1" width="1"/&gt;</description>
      <comments>http://devtalk.dk/CommentView,guid,f455512e-1fbe-4ea6-ad78-ee3f7c3003df.aspx</comments>
      <category>EF4</category>
      <category>Entity Framework</category>
    <feedburner:origLink>http://devtalk.dk/2009/08/03/Danish+Podcast+Entity+Framework+40+Beta+1.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://devtalk.dk/Trackback.aspx?guid=d5dccc2a-5723-49b4-97d1-bf759b7f592d</trackback:ping>
      <pingback:server>http://devtalk.dk/pingback.aspx</pingback:server>
      <pingback:target>http://devtalk.dk/PermaLink,guid,d5dccc2a-5723-49b4-97d1-bf759b7f592d.aspx</pingback:target>
      <dc:creator>Joachim Lykke Andersen</dc:creator>
      <wfw:comment>http://devtalk.dk/CommentView,guid,d5dccc2a-5723-49b4-97d1-bf759b7f592d.aspx</wfw:comment>
      <wfw:commentRss>http://devtalk.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=d5dccc2a-5723-49b4-97d1-bf759b7f592d</wfw:commentRss>
      
      <title>Entity Framework 4.0 Beta 1 – POCO Enum support?</title>
      <guid isPermaLink="false">http://devtalk.dk/PermaLink,guid,d5dccc2a-5723-49b4-97d1-bf759b7f592d.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevtalknetBlog/~3/bit3LY5DaH4/Entity+Framework+40+Beta+1+POCO+Enum+Support.aspx</link>
      <pubDate>Thu, 18 Jun 2009 06:16:50 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
One of the things that has not made it into Entity Framework 4.0 beta 1 is Enum support&#xD;
and &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/7659feab-d348-4367-b2cd-0456b20262fe"&gt;it&#xD;
is not planned for EF4&lt;/a&gt;. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
This seems like a strange decision, as it is wrong and not POCO at all if you have&#xD;
to change your classes to work around the lack of enum support in your persistance&#xD;
layer. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Around the internet people suggest that you can just make the property private, and&#xD;
then create a public property that exposes your value as your enum. But that is not&#xD;
quite the solution, as this is not going to work in Linq queries that execute at database&#xD;
level.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
While I was still trying to work around this, I came across &lt;a href="http://blogs.msdn.com/alexj/archive/2009/06/05/tip-23-how-to-fake-enums-in-ef-4.aspx"&gt;this&#xD;
post by Alex James&lt;/a&gt; that does exactly what I was attempting: to fake enum support.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Lets see how this will look if we implement our Status property on the Order entity&#xD;
to be an enum.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
The first thing we are going to do, is to change our Status property in the EF model&#xD;
to be a complex type. We can do that in the designer.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://devtalk.dk/content/binary/WindowsLiveWriter/EntityFramework4.0Beta1Enumsupport_C44/image_2.png"&gt;&#xD;
            &lt;img style="border-right-width: 0px; margin: 0px 0px 0px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://devtalk.dk/content/binary/WindowsLiveWriter/EntityFramework4.0Beta1Enumsupport_C44/image_thumb.png" width="340" height="292"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
First of all we create the complex type. Right click “Complex Types” in the model&#xD;
browser and choose “Create Complex Type”. We name it OrderStatusWrapper and add a&#xD;
scalar Int32 property called “Value” to it.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Then we delete the scalar Status property from the Order entity, and add a complex&#xD;
property instead. We name it Status like the old one, and in properties we set the&#xD;
type to “OrderStatusWrapper”. If we build now, the validator will complain that we&#xD;
forgot to map the property, so we get the table mapping window, and map the Status&#xD;
integer to the “Value” integer on our complex property. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://devtalk.dk/content/binary/WindowsLiveWriter/EntityFramework4.0Beta1Enumsupport_C44/image_4.png"&gt;&#xD;
            &lt;img style="border-right-width: 0px; margin: 0px 0px 0px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="left" src="http://devtalk.dk/content/binary/WindowsLiveWriter/EntityFramework4.0Beta1Enumsupport_C44/image_thumb_1.png" width="344" height="263"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Now we add the enum as usually:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    3&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;enum&lt;/span&gt;&lt;span style="color: #2b91af"&gt;OrderStatus&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    4&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    5&lt;/span&gt;     &lt;span style="color: #eee8aa"&gt;OrderCreated&lt;/span&gt;,&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    6&lt;/span&gt;     &lt;span style="color: #eee8aa"&gt;OrderPayed&lt;/span&gt;,&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    7&lt;/span&gt;     &lt;span style="color: #eee8aa"&gt;OrderShipped&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    8&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
Now we have to implement our OrderStatusWrapper, and make it do some work behind the&#xD;
scenes for us:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    1&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    2&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;class&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;OrderStatusWrapper&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    3&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    4&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;private&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;OrderStatus&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;_status&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    5&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    6&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;int&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Value&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    7&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    8&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt; (&lt;span style="color: #40c4ff"&gt;int&lt;/span&gt;)&lt;span style="color: #eee8aa"&gt;_status&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    9&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt; { &lt;span style="color: #eee8aa"&gt;_status&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;OrderStatus&lt;/span&gt;)&lt;span style="color: #40c4ff"&gt;value&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   10&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   11&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;OrderStatus&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;EnumValue&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   12&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   13&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;_status&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   14&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt; { &lt;span style="color: #eee8aa"&gt;_status&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;value&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   15&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   16&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   17&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;static&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;implicit&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;operator&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   18&lt;/span&gt;         &lt;span style="color: #eee8aa"&gt;OrderStatusWrapper&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;OrderStatus&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;status&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   19&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   20&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;new&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;OrderStatusWrapper&lt;/span&gt; { &lt;span style="color: #eee8aa"&gt;EnumValue&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;status&lt;/span&gt; };&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   21&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   22&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   23&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;static&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;implicit&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;operator&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   24&lt;/span&gt;         &lt;span style="color: #eee8aa"&gt;OrderStatus&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;OrderStatusWrapper&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;statusWrapper&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   25&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   26&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;if&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;statusWrapper&lt;/span&gt;&lt;span style="color: silver"&gt;==&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;null&lt;/span&gt;) &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   27&lt;/span&gt;             &lt;span style="color: #eee8aa"&gt;OrderStatus&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;OrderCreated&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   28&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;else&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;return&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;statusWrapper&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;EnumValue&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   29&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   30&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   31&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
To do this we need to do an implicit operator overloading – that is an implicit conversion&#xD;
between OrderStatusWrapper and OrderStatus, creating the illusion that Status really&#xD;
is an OrderStatus enum value.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Now we can actually do this:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   24&lt;/span&gt;             &lt;span style="color: #66cdaa"&gt;Order&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;o&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;new&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;Order&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   25&lt;/span&gt;             &lt;span style="color: #eee8aa"&gt;o&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;CreatedDate&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #2b91af"&gt;DateTime&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Now&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   26&lt;/span&gt;             &lt;span style="color: #eee8aa"&gt;o&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Status&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #2b91af"&gt;OrderStatus&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;OrderCreated&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   27&lt;/span&gt;             &lt;span style="color: #eee8aa"&gt;o&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Customer&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;custRep&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;First&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;x&lt;/span&gt;&lt;span style="color: silver"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;x&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Id&lt;/span&gt;&lt;span style="color: silver"&gt;==&lt;/span&gt;&lt;span style="color: #60ff60"&gt;1&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   28&lt;/span&gt;             &lt;span style="color: #eee8aa"&gt;orderRep&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Add&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;o&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
And we can use it in a query like so:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   24&lt;/span&gt; &lt;span style="color: #eee8aa"&gt;var&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;orders&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;from&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;o&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;in&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;orderRep&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;GetAll&lt;/span&gt;()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   25&lt;/span&gt;              &lt;span style="color: #40c4ff"&gt;where&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;o&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Status&lt;/span&gt;&lt;span style="color: silver"&gt;==&lt;/span&gt;&lt;span style="color: #2b91af"&gt;OrderStatus&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;OrderCreated&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   26&lt;/span&gt;              &lt;span style="color: #40c4ff"&gt;select&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;o&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
This is a fairly decent workaround, but it still bothers me that we have to declare&#xD;
our property with the type of the wrapper, and that we have to clutter our code with&#xD;
wrappers. This is behaviour to accommodate our choice of ORM. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
So we do need real enum support, but intill we do we seem to get by with this.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Resources&lt;/strong&gt;:&#xD;
&lt;/p&gt;&#xD;
        &lt;ul&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://blogs.msdn.com/alexj/archive/2009/06/05/tip-23-how-to-fake-enums-in-ef-4.aspx"&gt;Post&#xD;
by Alex James on faking enums&lt;/a&gt;&#xD;
          &lt;/li&gt;&#xD;
        &lt;/ul&gt;&#xD;
        &lt;img width="0" height="0" src="http://devtalk.dk/aggbug.ashx?id=d5dccc2a-5723-49b4-97d1-bf759b7f592d"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=bit3LY5DaH4:ttTeLzWyxxk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=bit3LY5DaH4:ttTeLzWyxxk:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=bit3LY5DaH4:ttTeLzWyxxk:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=bit3LY5DaH4:ttTeLzWyxxk:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=bit3LY5DaH4:ttTeLzWyxxk:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=bit3LY5DaH4:ttTeLzWyxxk:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=bit3LY5DaH4:ttTeLzWyxxk:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=bit3LY5DaH4:ttTeLzWyxxk:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=bit3LY5DaH4:ttTeLzWyxxk:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevtalknetBlog/~4/bit3LY5DaH4" height="1" width="1"/&gt;</description>
      <comments>http://devtalk.dk/CommentView,guid,d5dccc2a-5723-49b4-97d1-bf759b7f592d.aspx</comments>
      <category>Entity Framework</category>
      <category>EF4</category>
    <feedburner:origLink>http://devtalk.dk/2009/06/18/Entity+Framework+40+Beta+1+POCO+Enum+Support.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://devtalk.dk/Trackback.aspx?guid=fb6dd047-778c-416c-8d7a-afd36956b733</trackback:ping>
      <pingback:server>http://devtalk.dk/pingback.aspx</pingback:server>
      <pingback:target>http://devtalk.dk/PermaLink,guid,fb6dd047-778c-416c-8d7a-afd36956b733.aspx</pingback:target>
      <dc:creator>Joachim Lykke Andersen</dc:creator>
      <wfw:comment>http://devtalk.dk/CommentView,guid,fb6dd047-778c-416c-8d7a-afd36956b733.aspx</wfw:comment>
      <wfw:commentRss>http://devtalk.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=fb6dd047-778c-416c-8d7a-afd36956b733</wfw:commentRss>
      
      <title>Speaking at ANUG on Entity Framework 4.0 Beta 1 – Hands on look on the new bits</title>
      <guid isPermaLink="false">http://devtalk.dk/PermaLink,guid,fb6dd047-778c-416c-8d7a-afd36956b733.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevtalknetBlog/~3/DwShUCvA6lY/Speaking+At+ANUG+On+Entity+Framework+40+Beta+1+Hands+On+Look+On+The+New+Bits.aspx</link>
      <pubDate>Sat, 13 Jun 2009 22:28:21 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
I will be speaking at the June meeting of &lt;a href="http://www.anug.dk/post/2009/05/31/Junimc3b8de-Entity-Framework-40.aspx"&gt;ANUG&lt;/a&gt; covering&#xD;
the new bits in Entity Framework 4.0 Beta 1.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;When:&lt;/strong&gt;&#xD;
          &lt;br&gt;&#xD;
25/6 18:00&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Where:&lt;/strong&gt;&#xD;
          &lt;br&gt;&#xD;
Kamstrup A/S &#xD;
&lt;br&gt;&#xD;
Industrivej 28, Stilling &#xD;
&lt;br&gt;&#xD;
DK-8660 Skanderborg&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;&#xD;
            &lt;a href="http://www.anug.dk/post/2009/05/31/Junimc3b8de-Entity-Framework-40.aspx"&gt;Sign&#xD;
Up&lt;/a&gt;&#xD;
          &lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
It will be pretty hands on with focus on demoing the new stuff, starting out from&#xD;
the criticism of the first version of EF, to the wishlist for the next version. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Hope to see you there.&#xD;
&lt;/p&gt;&#xD;
        &lt;img width="0" height="0" src="http://devtalk.dk/aggbug.ashx?id=fb6dd047-778c-416c-8d7a-afd36956b733"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=DwShUCvA6lY:agAXox6t1Gg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=DwShUCvA6lY:agAXox6t1Gg:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=DwShUCvA6lY:agAXox6t1Gg:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=DwShUCvA6lY:agAXox6t1Gg:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=DwShUCvA6lY:agAXox6t1Gg:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=DwShUCvA6lY:agAXox6t1Gg:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=DwShUCvA6lY:agAXox6t1Gg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=DwShUCvA6lY:agAXox6t1Gg:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=DwShUCvA6lY:agAXox6t1Gg:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevtalknetBlog/~4/DwShUCvA6lY" height="1" width="1"/&gt;</description>
      <comments>http://devtalk.dk/CommentView,guid,fb6dd047-778c-416c-8d7a-afd36956b733.aspx</comments>
      <category>EF4</category>
      <category>Entity Framework</category>
    <feedburner:origLink>http://devtalk.dk/2009/06/13/Speaking+At+ANUG+On+Entity+Framework+40+Beta+1+Hands+On+Look+On+The+New+Bits.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://devtalk.dk/Trackback.aspx?guid=b5d9cad2-e155-423b-b66f-7ec287c5cb06</trackback:ping>
      <pingback:server>http://devtalk.dk/pingback.aspx</pingback:server>
      <pingback:target>http://devtalk.dk/PermaLink,guid,b5d9cad2-e155-423b-b66f-7ec287c5cb06.aspx</pingback:target>
      <dc:creator>Joachim Lykke Andersen</dc:creator>
      <wfw:comment>http://devtalk.dk/CommentView,guid,b5d9cad2-e155-423b-b66f-7ec287c5cb06.aspx</wfw:comment>
      <wfw:commentRss>http://devtalk.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=b5d9cad2-e155-423b-b66f-7ec287c5cb06</wfw:commentRss>
      <slash:comments>12</slash:comments>
      
      <title>Entity Framework 4.0 Beta 1 – POCO, ObjectSet&lt;T&gt;, Repository&lt;T&gt; and UnitOfWork</title>
      <guid isPermaLink="false">http://devtalk.dk/PermaLink,guid,b5d9cad2-e155-423b-b66f-7ec287c5cb06.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevtalknetBlog/~3/imEBLD3lScE/Entity+Framework+40+Beta+1+POCO+ObjectSet+Repository+And+UnitOfWork.aspx</link>
      <pubDate>Tue, 09 Jun 2009 19:15:28 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
In the old Entity Framework, creating a generic repository wasn’t impossible, but&#xD;
not really elegant either. Any way you looked at it, you needed to deal with strings&#xD;
to get it working.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Lets say you want to create an Add method on your repository, there was no way getting&#xD;
around something like this:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    6&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    7&lt;/span&gt;         &lt;span style="color: #eee8aa"&gt;objectContext&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;AddObject&lt;/span&gt;(&lt;span style="color: #60ff60"&gt;"OrderSet"&lt;/span&gt;, &lt;span style="color: #eee8aa"&gt;newOrder&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    8&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
So for each (base) entity you have in your conceptual model you have a corresponding&#xD;
EntitySet, and in EF1 you needed to pass in the string name of the entityset to add&#xD;
the object; the name is not necessarily the same as the name of the entity. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
In a generic repository you would have to figure out the name of the current entityset&#xD;
– you can figure it out with a bit of reflection on the concrete ObjectContext, but&#xD;
its not pretty, errorprone and it took me a while to get there. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Enter ObjectSet&amp;lt;T&amp;gt;&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Fortunately in EF4 the strongly typed properties on the ObjectContext for each EntitySet&#xD;
return ObjectSet&amp;lt;T&amp;gt; instead of ObjectQuery&amp;lt;T&amp;gt;. And since the ObjectContext&#xD;
also has a method called CreateObjectSet&amp;lt;T&amp;gt; you can instead do something like&#xD;
this:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    1&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    2&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;private&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;IObjectSet&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ObjectSet&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    3&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    4&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    5&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    6&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;if&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;_objectSet&lt;/span&gt;&lt;span style="color: silver"&gt;==&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;null&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    7&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    8&lt;/span&gt;             &lt;span style="color: #eee8aa"&gt;_objectSet&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;this&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Context&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;CreateObjectSet&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    9&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   10&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;_objectSet&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   11&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   12&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   13&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   14&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;void&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Add&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;entity&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   15&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   16&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;this&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ObjectSet&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;AddObject&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;entity&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   17&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   18&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
Notice the IObjectSet&amp;lt;T&amp;gt;  which is very handy as it enables you to fake&#xD;
the ObjectSet for testing for instance. Now to be fair, this is how it should have&#xD;
been in EF1, but on an optimistic note im happy its changed.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Repository&amp;lt;T&amp;gt;&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
In order to have the right context for testing EF4 properly with persistance ignorance&#xD;
and POCO we will set up a Repository and UnitOfWork pattern for the OrderModel project&#xD;
i did in my previous EF4 post. Im not going to cover every detail of this, but I will&#xD;
run through the setup, and then you can get the code and have a closer look on your&#xD;
own.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
First i set up the repository contract and create an IRepository&amp;lt;T&amp;gt; where T&#xD;
is a POCO class.&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    1&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    2&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;interface&lt;/span&gt;&lt;span style="color: #2b91af"&gt;IRepository&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;where&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt; : &lt;span style="color: #40c4ff"&gt;class&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    3&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    4&lt;/span&gt;     &lt;span style="color: #eee8aa"&gt;IQueryable&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;GetQuery&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    5&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    6&lt;/span&gt;     &lt;span style="color: #eee8aa"&gt;IEnumerable&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;GetAll&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    7&lt;/span&gt;     &lt;span style="color: #eee8aa"&gt;IEnumerable&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Find&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;Func&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;, &lt;span style="color: #40c4ff"&gt;bool&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;where&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    8&lt;/span&gt;     &lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Single&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;Func&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;, &lt;span style="color: #40c4ff"&gt;bool&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;where&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    9&lt;/span&gt;     &lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;First&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;Func&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;, &lt;span style="color: #40c4ff"&gt;bool&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;where&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   10&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   11&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;void&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Delete&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;entity&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   12&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;void&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Add&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;entity&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   13&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;void&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Attach&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;entity&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   14&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;void&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;SaveChanges&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   15&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   16&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
Next we will define a generic repository for the Entity Framework that implements&#xD;
IRepository&amp;lt;T&amp;gt;:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    1&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    2&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;class&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;EFRepository&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt; : &lt;span style="color: #eee8aa"&gt;IRepository&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;where&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt; : &lt;span style="color: #40c4ff"&gt;class&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    3&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    4&lt;/span&gt;     &lt;span style="color: #eee8aa"&gt;ObjectContext&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;_context&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    5&lt;/span&gt;     &lt;span style="color: #eee8aa"&gt;IObjectSet&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;_objectSet&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    6&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    7&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;private&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ObjectContext&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Context&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    8&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    9&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   10&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   11&lt;/span&gt;             &lt;span style="color: #40c4ff"&gt;if&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;_context&lt;/span&gt;&lt;span style="color: silver"&gt;==&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;null&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   12&lt;/span&gt;            &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   13&lt;/span&gt;                 &lt;span style="color: #eee8aa"&gt;_context&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;GetCurrentUnitOfWork&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   14&lt;/span&gt;                     &lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;EFUnitOfWork&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;()&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Context&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   15&lt;/span&gt;            &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   16&lt;/span&gt;             &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;_context&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   17&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   18&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   19&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   20&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;private&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;IObjectSet&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ObjectSet&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   21&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   22&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   23&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   24&lt;/span&gt;             &lt;span style="color: #40c4ff"&gt;if&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;_objectSet&lt;/span&gt;&lt;span style="color: silver"&gt;==&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;null&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   25&lt;/span&gt;            &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   26&lt;/span&gt;                 &lt;span style="color: #eee8aa"&gt;_objectSet&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;this&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Context&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   27&lt;/span&gt;                     &lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;CreateObjectSet&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   28&lt;/span&gt;            &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   29&lt;/span&gt;             &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;_objectSet&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   30&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   31&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   32&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   33&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;TUnitOfWork&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;GetCurrentUnitOfWork&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;TUnitOfWork&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;() &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   34&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;where&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;TUnitOfWork&lt;/span&gt; : &lt;span style="color: #eee8aa"&gt;IUnitOfWork&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   35&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   36&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;TUnitOfWork&lt;/span&gt;)&lt;span style="color: #eee8aa"&gt;UnitOfWork&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Current&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   37&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   38&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   39&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;IQueryable&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;GetQuery&lt;/span&gt;()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   40&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   41&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ObjectSet&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   42&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   43&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   44&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;IEnumerable&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;GetAll&lt;/span&gt;()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   45&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   46&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;GetQuery&lt;/span&gt;()&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ToList&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   47&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   48&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   49&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;IEnumerable&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Find&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;Func&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;, &lt;span style="color: #40c4ff"&gt;bool&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;where&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   50&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   51&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;this&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ObjectSet&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Where&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;where&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   52&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   53&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   54&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Single&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;Func&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;, &lt;span style="color: #40c4ff"&gt;bool&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;where&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   55&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   56&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;this&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ObjectSet&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Single&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;where&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   57&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   58&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   59&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;First&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;Func&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;, &lt;span style="color: #40c4ff"&gt;bool&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;where&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   60&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   61&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;this&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ObjectSet&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;First&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;where&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   62&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   63&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   64&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;void&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Delete&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;entity&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   65&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   66&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;this&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ObjectSet&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;DeleteObject&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;entity&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   67&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   68&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   69&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;void&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Add&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;entity&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   70&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   71&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;this&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ObjectSet&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;AddObject&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;entity&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   72&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   73&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   74&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;void&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Attach&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;T&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;entity&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   75&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   76&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;this&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ObjectSet&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Attach&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;entity&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   77&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   78&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   79&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;void&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;SaveChanges&lt;/span&gt;()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   80&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   81&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;this&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Context&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;SaveChanges&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   82&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   83&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   84&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
Now thats pretty straight forward. The ObjectContext actually already works like a&#xD;
UnitOfWork, but in order to handle the lifespan of our ObjectContext we wrap it up&#xD;
in our own UnitOfWork implementation. &#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    1&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    2&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;class&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;EFUnitOfWork&lt;/span&gt; : &lt;span style="color: #eee8aa"&gt;IUnitOfWork&lt;/span&gt;, &lt;span style="color: #eee8aa"&gt;IDisposable&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    3&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    4&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ObjectContext&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Context&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;private&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    5&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    6&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;EFUnitOfWork&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;ObjectContext&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;context&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    7&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    8&lt;/span&gt;         &lt;span style="color: #eee8aa"&gt;Context&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;context&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    9&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   10&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   11&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;void&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Commit&lt;/span&gt;()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   12&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   13&lt;/span&gt;         &lt;span style="color: #eee8aa"&gt;Context&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;SaveChanges&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   14&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   15&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   16&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;void&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Dispose&lt;/span&gt;()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   17&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   18&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;if&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;Context&lt;/span&gt;&lt;span style="color: silver"&gt;!=&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;null&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   19&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   20&lt;/span&gt;             &lt;span style="color: #eee8aa"&gt;Context&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Dispose&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   21&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   22&lt;/span&gt;         &lt;span style="color: #eee8aa"&gt;GC&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;SuppressFinalize&lt;/span&gt;(&lt;span style="color: #40c4ff"&gt;this&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   23&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   24&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   25&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
IUnitOfWork consists of the method  Commit, and in our concrete implementation&#xD;
we save changes on our current ObjectContext on commmit.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
To handle units of work we implement a static class that handles both the case of&#xD;
a webcontext and a multithreaded non web context. The ObjectContext is not threadsafe,&#xD;
so we need to take that in consideration. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
The interesting bit of that class is the Current property that gets the current UnitOfWork:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    1&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    2&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;static&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;IUnitOfWork&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Current&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    3&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    4&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    5&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    6&lt;/span&gt;         &lt;span style="color: #eee8aa"&gt;IUnitOfWork&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;unitOfWork&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;GetUnitOfWork&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    7&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;if&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;unitOfWork&lt;/span&gt;&lt;span style="color: silver"&gt;==&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;null&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    8&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    9&lt;/span&gt;             &lt;span style="color: #eee8aa"&gt;_unitOfWorkFactory&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ObjectFactory&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   10&lt;/span&gt;                         &lt;span style="color: #eee8aa"&gt;GetInstance&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;IUnitOfWorkFactory&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   11&lt;/span&gt;             &lt;span style="color: #eee8aa"&gt;unitOfWork&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;_unitOfWorkFactory&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Create&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   12&lt;/span&gt;             &lt;span style="color: #eee8aa"&gt;SaveUnitOfWork&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;unitOfWork&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   13&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   14&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;unitOfWork&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   15&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   16&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   17&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
We are going to look at the two methods that do the work in a moment, but first of&#xD;
all notice that we have a UnitOfWorkFactory to produce our specific UnitOfWork. Furthermore&#xD;
we are going to use the &lt;a href="http://structuremap.sourceforge.net/Default.htm"&gt;StructureMap&lt;/a&gt; Service&#xD;
Locator to get our dependency on a concrete factory. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Either in configuration or in code we need to set up which concrete type the requested&#xD;
type should resolve to like so. In code it would be something like this:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    2&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    3&lt;/span&gt; &lt;span style="color: #66cdaa"&gt;ObjectFactory&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Initialize&lt;/span&gt;(&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    4&lt;/span&gt;     &lt;span style="color: #eee8aa"&gt;x&lt;/span&gt;&lt;span style="color: silver"&gt;=&amp;gt;&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    5&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    6&lt;/span&gt;         &lt;span style="color: #eee8aa"&gt;x&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ForRequestedType&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;IUnitOfWorkFactory&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;()&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    7&lt;/span&gt;             &lt;span style="color: #eee8aa"&gt;TheDefaultIsConcreteType&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;EFUnitOfWorkFactory&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    8&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    9&lt;/span&gt;         &lt;span style="color: #eee8aa"&gt;x&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ForRequestedType&lt;/span&gt;(&lt;span style="color: #40c4ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;IRepository&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&amp;gt;&lt;/span&gt;))&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   10&lt;/span&gt;             &lt;span style="color: #eee8aa"&gt;TheDefaultIsConcreteType&lt;/span&gt;(&lt;span style="color: #40c4ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;EFRepository&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&amp;gt;&lt;/span&gt;));&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   11&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   12&lt;/span&gt; );&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   13&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
We map it to the concrete factory implementation for our Entity Framework project.&#xD;
The IRepository&amp;lt;T&amp;gt; is also mapped to the concrete type EFRepository that we&#xD;
created earlier.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
The EFUnitOfWork factory has the responsibility of creating new units of work, implements&#xD;
the IUnitOfWorkFactory and has a method that takes a delegate which, when called creates&#xD;
an instance of the ObjectContext we want to work on.&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    1&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    2&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;class&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;EFUnitOfWorkFactory&lt;/span&gt; : &lt;span style="color: #eee8aa"&gt;IUnitOfWorkFactory&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    3&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    4&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;private&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;static&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Func&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ObjectContext&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;_objectContextDelegate&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    5&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;private&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;static&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;readonly&lt;/span&gt; Object &lt;span style="color: #eee8aa"&gt;_lockObject&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;new&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;object&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    6&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    7&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;static&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;void&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;SetObjectContext&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    8&lt;/span&gt;        &#xD;
(&lt;span style="color: #eee8aa"&gt;Func&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ObjectContext&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;objectContextDelegate&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    9&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   10&lt;/span&gt;         &lt;span style="color: #eee8aa"&gt;_objectContextDelegate&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;objectContextDelegate&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   11&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   12&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   13&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;IUnitOfWork&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Create&lt;/span&gt;()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   14&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   15&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;lock&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;_lockObject&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   16&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   17&lt;/span&gt;             &lt;span style="color: #eee8aa"&gt;ObjectContext&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;context&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;_objectContextDelegate&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   18&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   19&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;new&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;EFUnitOfWork&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;context&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   20&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   21&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   22&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;UnitOfWork/ObjectContext lifespan&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
So back to the UnitOfWork. As mentioned the ObjectContext is not threadsafe, so we&#xD;
need to make sure that when re-using the objectcontext we dont run into issues with&#xD;
that. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
If we are in a web-application we probably want to at least scope the context to maximum&#xD;
the lenght of the request. If we tied it to a static class member, it would share&#xD;
lifespan with the AppDomain and that is bound to cause problems. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Maybe it would make sense to work in smaller cohesive chunks of one or few business&#xD;
transactions and you could create a UnitOfWork scope to handle that, but for the sake&#xD;
of the example we are going to tie it to HttpContext.Current.Items and thereby limit&#xD;
the lifespan to the current request.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
When we are not in a web application we need to handle multithreaded scenarios at&#xD;
least, and it would probably make most sense to have a scope of a business transaction,&#xD;
but in this context ill just handle the threading issue. This leaves us with the following&#xD;
methods on UnitOfWork where _threads is a Hashtable:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    1&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    2&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;private&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;static&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;IUnitOfWork&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;GetUnitOfWork&lt;/span&gt;()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    3&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    4&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;if&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;HttpContext&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Current&lt;/span&gt;&lt;span style="color: silver"&gt;!=&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;null&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    5&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    6&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;if&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;HttpContext&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Current&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Items&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    7&lt;/span&gt;                     &lt;span style="color: #eee8aa"&gt;Contains&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;HTTPCONTEXTKEY&lt;/span&gt;))&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    8&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    9&lt;/span&gt;             &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;IUnitOfWork&lt;/span&gt;)&lt;span style="color: #eee8aa"&gt;HttpContext&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Current&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   10&lt;/span&gt;                                     &lt;span style="color: #eee8aa"&gt;Items&lt;/span&gt;[&lt;span style="color: #eee8aa"&gt;HTTPCONTEXTKEY&lt;/span&gt;];&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   11&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   12&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;null&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   13&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   14&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;else&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   15&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   16&lt;/span&gt;         &lt;span style="color: #eee8aa"&gt;Thread&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;thread&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Thread&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;CurrentThread&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   17&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;if&lt;/span&gt; (&lt;span style="color: #40c4ff"&gt;string&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;IsNullOrEmpty&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;thread&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Name&lt;/span&gt;))&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   18&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   19&lt;/span&gt;             &lt;span style="color: #eee8aa"&gt;thread&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Name&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Guid&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;NewGuid&lt;/span&gt;()&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ToString&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   20&lt;/span&gt;             &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;null&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   21&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   22&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;else&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   23&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   24&lt;/span&gt;             &lt;span style="color: #40c4ff"&gt;lock&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;_threads&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;SyncRoot&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   25&lt;/span&gt;            &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   26&lt;/span&gt;                 &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;IUnitOfWork&lt;/span&gt;)&lt;span style="color: #eee8aa"&gt;_threads&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   27&lt;/span&gt;                    &#xD;
[&lt;span style="color: #eee8aa"&gt;Thread&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;CurrentThread&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Name&lt;/span&gt;];&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   28&lt;/span&gt;            &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   29&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   30&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   31&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   32&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   33&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;private&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;static&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;void&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;SaveUnitOfWork&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;IUnitOfWork&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;unitOfWork&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   34&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   35&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;if&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;HttpContext&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Current&lt;/span&gt;&lt;span style="color: silver"&gt;!=&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;null&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   36&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   37&lt;/span&gt;         &lt;span style="color: #eee8aa"&gt;HttpContext&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Current&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Items&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   38&lt;/span&gt;                    &#xD;
[&lt;span style="color: #eee8aa"&gt;HTTPCONTEXTKEY&lt;/span&gt;] &lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;unitOfWork&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   39&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   40&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;else&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   41&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   42&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;lock&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;_threads&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;SyncRoot&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   43&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   44&lt;/span&gt;             &lt;span style="color: #eee8aa"&gt;_threads&lt;/span&gt;[&lt;span style="color: #eee8aa"&gt;Thread&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;CurrentThread&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Name&lt;/span&gt;] &lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;unitOfWork&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   45&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   46&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   47&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   48&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Conclusion&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
So we end up being able to write the following code:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    5&lt;/span&gt; &lt;span style="color: #eee8aa"&gt;IRepository&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Order&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;orderRep&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ObjectFactory&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    6&lt;/span&gt;     &lt;span style="color: #eee8aa"&gt;GetInstance&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;IRepository&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Order&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&amp;gt;&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    7&lt;/span&gt; &lt;span style="color: #eee8aa"&gt;IRepository&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Customer&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;custRep&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ObjectFactory&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    8&lt;/span&gt;     &lt;span style="color: #eee8aa"&gt;GetInstance&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;IRepository&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Customer&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&amp;gt;&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    9&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   10&lt;/span&gt; &lt;span style="color: #eee8aa"&gt;Order&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;o&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;new&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Order&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   11&lt;/span&gt; &lt;span style="color: #eee8aa"&gt;o&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;CreatedDate&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;DateTime&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Now&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   12&lt;/span&gt; &lt;span style="color: #eee8aa"&gt;o&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Status&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #60ff60"&gt;100&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   13&lt;/span&gt; &lt;span style="color: #eee8aa"&gt;o&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Customer&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;custRep&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;First&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;x&lt;/span&gt;&lt;span style="color: silver"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;x&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Id&lt;/span&gt;&lt;span style="color: silver"&gt;==&lt;/span&gt;&lt;span style="color: #60ff60"&gt;1&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   14&lt;/span&gt; &lt;span style="color: #eee8aa"&gt;orderRep&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Add&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;o&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
We are programming against the interfaces and we use our POCO classes. We hook up&#xD;
our concrete DB dependend implementations with the StructureMap Service Locator, and&#xD;
we have control over the scope and lifespan with our UnitOfWork implementation.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
But have a look at the code. Be advised though - it is not production ready code –&#xD;
it needs tests, guards and errorhandling, and it serves only as a sort of Proof of&#xD;
concept for EF4.&#xD;
&lt;/p&gt;&#xD;
        &lt;ul&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://devtalk.dk/content/binary/Devtalk.Shop.rar"&gt;Download the source for&#xD;
the post (2,5 MB)&lt;/a&gt;&#xD;
          &lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://www.codeplex.com/ncommon"&gt;NCommon&lt;/a&gt;&#xD;
          &lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://blog.keithpatton.com/2009/05/30/Entity+Framework+POCO+Repository+Using+Visual+Studio+2010+Net+40+Beta+1.aspx"&gt;POCO&#xD;
example on Keith Pattons blog&lt;/a&gt;&#xD;
          &lt;/li&gt;&#xD;
        &lt;/ul&gt;&#xD;
        &lt;img width="0" height="0" src="http://devtalk.dk/aggbug.ashx?id=b5d9cad2-e155-423b-b66f-7ec287c5cb06"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=imEBLD3lScE:F10czfA-phA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=imEBLD3lScE:F10czfA-phA:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=imEBLD3lScE:F10czfA-phA:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=imEBLD3lScE:F10czfA-phA:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=imEBLD3lScE:F10czfA-phA:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=imEBLD3lScE:F10czfA-phA:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=imEBLD3lScE:F10czfA-phA:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=imEBLD3lScE:F10czfA-phA:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=imEBLD3lScE:F10czfA-phA:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevtalknetBlog/~4/imEBLD3lScE" height="1" width="1"/&gt;</description>
      <comments>http://devtalk.dk/CommentView,guid,b5d9cad2-e155-423b-b66f-7ec287c5cb06.aspx</comments>
      <category>EF4</category>
      <category>Entity Framework</category>
    <feedburner:origLink>http://devtalk.dk/2009/06/09/Entity+Framework+40+Beta+1+POCO+ObjectSet+Repository+And+UnitOfWork.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://devtalk.dk/Trackback.aspx?guid=70735551-fa79-472f-831b-9744596fbfa9</trackback:ping>
      <pingback:server>http://devtalk.dk/pingback.aspx</pingback:server>
      <pingback:target>http://devtalk.dk/PermaLink,guid,70735551-fa79-472f-831b-9744596fbfa9.aspx</pingback:target>
      <dc:creator>Joachim Lykke Andersen</dc:creator>
      <wfw:comment>http://devtalk.dk/CommentView,guid,70735551-fa79-472f-831b-9744596fbfa9.aspx</wfw:comment>
      <wfw:commentRss>http://devtalk.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=70735551-fa79-472f-831b-9744596fbfa9</wfw:commentRss>
      <slash:comments>9</slash:comments>
      
      <title>Entity Framework 4.0 Beta 1 – POCO Lazy Load and Code Generation of ObjectContext</title>
      <guid isPermaLink="false">http://devtalk.dk/PermaLink,guid,70735551-fa79-472f-831b-9744596fbfa9.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevtalknetBlog/~3/oX7sXYTkp0k/Entity+Framework+40+Beta+1+POCO+Lazy+Load+And+Code+Generation+Of+ObjectContext.aspx</link>
      <pubDate>Tue, 26 May 2009 21:05:15 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
In my &lt;a href="http://devtalk.dk/2009/05/22/Entity+Framework+40+How+To+POCO.aspx"&gt;first&#xD;
post about the 4.0 beta 1 bits&lt;/a&gt; I explored how we can work with our own POCO classes&#xD;
with the Entity Framework. In this post I will expand the example a little and figure&#xD;
out if and how we can do automatic lazy loading. Furthermore i will see if I can use&#xD;
the build in T4 template support to autogenerate an ObjectContext for our POCO entities.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;The Model&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
I want to create a common scenario with an order, orderline, product and customer,&#xD;
so I start out with writing the following classes:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    1&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;class&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;Customer&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    2&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    3&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;virtual&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ICollection&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;Order&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Orders&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    4&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&#xD;
virtual &lt;/span&gt;&lt;span style="color: #40c4ff"&gt;int&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Id&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    5&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&#xD;
virtual &lt;/span&gt;&lt;span style="color: #40c4ff"&gt;string&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;FirstName&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    6&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&#xD;
virtual &lt;/span&gt;&lt;span style="color: #40c4ff"&gt;string&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;LastName&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    7&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&#xD;
virtual &lt;/span&gt;&lt;span style="color: #40c4ff"&gt;string&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Address&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    8&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&#xD;
virtual &lt;/span&gt;&lt;span style="color: #40c4ff"&gt;string&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Email&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    9&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   10&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;class&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;Order&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   11&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   12&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;virtual&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ICollection&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;OrderLine&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   13&lt;/span&gt;         &lt;span style="color: #eee8aa"&gt;OrderLines&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   14&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;virtual&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;Customer&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Customer&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   15&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&#xD;
virtual &lt;/span&gt;&lt;span style="color: #40c4ff"&gt;int&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Id&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   16&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&#xD;
virtual &lt;/span&gt;&lt;span style="color: #eee8aa"&gt;DateTime&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;CreatedDate&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   17&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&#xD;
virtual &lt;/span&gt;&lt;span style="color: #40c4ff"&gt;int&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Status&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   18&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   19&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;class&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;OrderLine&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   20&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   21&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;virtual&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;Product&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Product&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   22&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;virtual&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;Order&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Order&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   23&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&#xD;
virtual &lt;/span&gt;&lt;span style="color: #40c4ff"&gt;int&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Id&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   24&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&#xD;
virtual &lt;/span&gt;&lt;span style="color: #40c4ff"&gt;double&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ItemPrice&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   25&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&#xD;
virtual &lt;/span&gt;&lt;span style="color: #40c4ff"&gt;int&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Quantity&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   26&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   27&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;class&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;Product&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   28&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   29&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;virtual&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ICollection&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;OrderLine&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   30&lt;/span&gt;         &lt;span style="color: #eee8aa"&gt;OrderLines&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   31&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&#xD;
virtual &lt;/span&gt;&lt;span style="color: #40c4ff"&gt;int&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Id&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   32&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&#xD;
virtual &lt;/span&gt;&lt;span style="color: #40c4ff"&gt;string&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Name&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   33&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&#xD;
virtual &lt;/span&gt;&lt;span style="color: #40c4ff"&gt;string&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Description&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   34&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&#xD;
virtual &lt;/span&gt;&lt;span style="color: #40c4ff"&gt;double&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Price&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   35&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
Then I go ahead and create the Entity Framework Model exactly like the Poco classes. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://devtalk.dk/content/binary/WindowsLiveWriter/Ent.0Beta1POCOLazyloadandcodegenerationo_343/image_4.png"&gt;&#xD;
            &lt;img style="border-right-width: 0px; margin: 0px 0px 0px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://devtalk.dk/content/binary/WindowsLiveWriter/Ent.0Beta1POCOLazyloadandcodegenerationo_343/image_thumb_1.png" width="400" height="487"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Notice the navigation properties have the right pluralization. If you generate your&#xD;
Entity Model from an existing database notize that you now have the option to pluralize&#xD;
or singularize generated object names:&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://devtalk.dk/content/binary/WindowsLiveWriter/Ent.0Beta1POCOLazyloadandcodegenerationo_343/image_8.png"&gt;&#xD;
            &lt;img style="border-right-width: 0px; margin: 0px 0px 0px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://devtalk.dk/content/binary/WindowsLiveWriter/Ent.0Beta1POCOLazyloadandcodegenerationo_343/image_thumb_3.png" width="400" height="355"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;T4 Code Generation&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
This time I dont want to manually write my objectcontext implementation. I want to&#xD;
code generate it, so that when i update my Entity Model the ObjectContext is automatically&#xD;
updated as well. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
In version 1.0 of the Entity Framework you had to create a SingleFileGenerator and&#xD;
hook into EFs codegeneration events, and it was not a very likeable costumization&#xD;
story. Because of all the feedback on this, The ADO.Net Team decided to handle code&#xD;
generation with T4 templates instead. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
This is truly sweet, and as it is deeply integrated with the Entity Framework its&#xD;
very easy to get started. As an example we will add a t4 template generator to our&#xD;
project and modify it to work with our POCO classes.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://devtalk.dk/content/binary/WindowsLiveWriter/Ent.0Beta1POCOLazyloadandcodegenerationo_343/image_10.png"&gt;&#xD;
            &lt;img style="border-right-width: 0px; margin: 0px 0px 0px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://devtalk.dk/content/binary/WindowsLiveWriter/Ent.0Beta1POCOLazyloadandcodegenerationo_343/image_thumb_4.png" width="400" height="308"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
First we select our .edmx file and go to the entity designer. Then we right-click&#xD;
anywhere on the workarea and choose “Add new Artifact Generation Item”. Then we choose&#xD;
the ADO.NET EntityObject Generator:&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://devtalk.dk/content/binary/WindowsLiveWriter/Ent.0Beta1POCOLazyloadandcodegenerationo_343/image_12.png"&gt;&#xD;
            &lt;img style="border-right-width: 0px; margin: 0px 0px 0px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://devtalk.dk/content/binary/WindowsLiveWriter/Ent.0Beta1POCOLazyloadandcodegenerationo_343/image_thumb_5.png" width="400" height="292"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
This creates a .tt file with a sub .cs file. The .tt file is the template and the&#xD;
sub cs. file is the result of running the code generation on the template. When you&#xD;
change the .tt file and save the .cs file will be updated – you can also right click&#xD;
the .tt file and choose “Run custom tool”.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Now we open op the template file, and its not really as nice an interface as we are&#xD;
used to with Visual Studio – no syntax-highlighting or intellisense really makes it&#xD;
a challenge to edit:&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://devtalk.dk/content/binary/WindowsLiveWriter/Ent.0Beta1POCOLazyloadandcodegenerationo_343/image_14.png"&gt;&#xD;
            &lt;img style="border-right-width: 0px; margin: 0px 0px 0px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://devtalk.dk/content/binary/WindowsLiveWriter/Ent.0Beta1POCOLazyloadandcodegenerationo_343/image_thumb_6.png" width="400" height="333"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
To fix that we use the brand new Extension Manager (Tools &amp;gt; Extension Manager)&#xD;
in Visual Studio to get the Free Edition of the &lt;a href="http://tangibleengineering.blogspot.com/2009/05/tangible-t4-editor-now-listed-in-visual.html"&gt;Tangible&#xD;
T4 editor&lt;/a&gt; – its not as feature rich as the &lt;a href="http://www.visualt4.com/"&gt;Clarius&#xD;
Visual T4&lt;/a&gt; one, but its free and a huge improvement:&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://devtalk.dk/content/binary/WindowsLiveWriter/Ent.0Beta1POCOLazyloadandcodegenerationo_343/image_20.png"&gt;&#xD;
            &lt;img style="border-right-width: 0px; margin: 0px 0px 0px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://devtalk.dk/content/binary/WindowsLiveWriter/Ent.0Beta1POCOLazyloadandcodegenerationo_343/image_thumb_9.png" width="400" height="312"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
This makes our template file look a lot more appealing, and the intellisense is simply&#xD;
invaluable – trust me, you need this one. The .tt file now looks like this:&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://devtalk.dk/content/binary/WindowsLiveWriter/Ent.0Beta1POCOLazyloadandcodegenerationo_343/image_22.png"&gt;&#xD;
            &lt;img style="border-right-width: 0px; margin: 0px 0px 0px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://devtalk.dk/content/binary/WindowsLiveWriter/Ent.0Beta1POCOLazyloadandcodegenerationo_343/image_thumb_10.png" width="400" height="335"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
So now we are equipped to remove the bits of the code generation that we don’t want.&#xD;
We want to get rid of any entities being generated and leave only the context bits.&#xD;
Its basically three sections that need to go - see the attached project for the resulting&#xD;
file. We also need to add an import to the namespace that contains our Poco classes,&#xD;
as so that these classes are used instead of the generated entities that we just have&#xD;
removed.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Requirements for Using Persistence-Ignorant Objects&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
In order to support deferred loading of related objects and change tracking some requirements&#xD;
do need to be fulfilled by the POCO classes. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
What happens behind the scenes is, that a proxy object is created that inherits from&#xD;
your POCO object. This proxy object is responsible for handling lazy loading and change&#xD;
tracking. &lt;a href="http://msdn.microsoft.com/en-us/library/dd468057(VS.100).aspx"&gt;The&#xD;
requirements are&lt;/a&gt;:&#xD;
&lt;/p&gt;&#xD;
        &lt;ul&gt;&#xD;
          &lt;li&gt;&#xD;
Poco class must be public, and not sealed or abstract, and implement a default constructor&#xD;
with no parameters. &#xD;
&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Poco class must NOT implement IEntityWithChangeTracker or IEntityWithRelationShips. &#xD;
&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Poco class properties mapped to conceptual model must be public and virtual. &#xD;
&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
The mapped Navigational property must be declared virtual and must not be sealed. &#xD;
&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
One-to-Many and Many-to-Many navigational property (OrderLine on Order for instance) &#xD;
must be mapped to properties that return a type implementing ICollection. &#xD;
&lt;/li&gt;&#xD;
        &lt;/ul&gt;&#xD;
        &lt;p&gt;&#xD;
There are actually generated two kinds of proxies: One that handles lazy loading and&#xD;
one that handles change tracking. If you only mark navigational properties virtual,&#xD;
you will not get the change tracking proxies.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Eager Load vs. Lazy Load&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
So now we want to try out out, and we could do something like this:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    1&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    2&lt;/span&gt;&#xD;
            &lt;span style="color: #40c4ff"&gt;using&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;var&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;context&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;new&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;OrderModelContainer&lt;/span&gt;())&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    3&lt;/span&gt;{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    4&lt;/span&gt;     &lt;span style="color: #eee8aa"&gt;var&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;orders&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;from&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;o&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;in&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;context&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;OrderSet&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;select&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;o&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    5&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    6&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;var&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;order&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;in&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;orders&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    7&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    8&lt;/span&gt;         &lt;span style="color: #eee8aa"&gt;Console&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;WriteLine&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;order&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;CreatedDate&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    9&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;var&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;orderline&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;in&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;order&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;OrderLines&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   10&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   11&lt;/span&gt;             &lt;span style="color: #eee8aa"&gt;Console&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;WriteLine&lt;/span&gt;(&lt;span style="color: #60ff60"&gt;" &#xD;
"&lt;/span&gt;&lt;span style="color: silver"&gt;+&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;orderline&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Quantity&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   12&lt;/span&gt;                         &lt;span style="color: silver"&gt;+&lt;/span&gt;&lt;span style="color: #60ff60"&gt;"&#xD;
"&lt;/span&gt;&lt;span style="color: silver"&gt;+&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;orderline&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Product&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Name&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   13&lt;/span&gt;                         &lt;span style="color: silver"&gt;+&lt;/span&gt;&lt;span style="color: #60ff60"&gt;"&#xD;
of $"&lt;/span&gt;&lt;span style="color: silver"&gt;+&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;orderline&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ItemPrice&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   14&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   15&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   16&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
We try to print the orderlines for each order – but the result is without the orderlines:&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://devtalk.dk/content/binary/WindowsLiveWriter/Ent.0Beta1POCOLazyloadandcodegenerationo_343/image_24.png"&gt;&#xD;
            &lt;img style="border-right-width: 0px; margin: 0px 0px 0px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://devtalk.dk/content/binary/WindowsLiveWriter/Ent.0Beta1POCOLazyloadandcodegenerationo_343/image_thumb_11.png" width="250" height="123"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
In Entity Framework version 1.0 we would have to explicitly eager load the related&#xD;
objects, and you can of course still do this:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    6&lt;/span&gt; &lt;span style="color: #eee8aa"&gt;var&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;orders&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;from&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;o&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;in&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    7&lt;/span&gt;              &lt;span style="color: #eee8aa"&gt;context&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;OrderSet&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Include&lt;/span&gt;(&lt;span style="color: #60ff60"&gt;"OrderLines.Product"&lt;/span&gt;) &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    8&lt;/span&gt;              &lt;span style="color: #eee8aa"&gt;select&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;o&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
In many situations this is a good thing, as you have control over how many times your&#xD;
database is hit on a query, but it also clutters your code with at lot of explicit&#xD;
includes, and more often than not developers are surprised that the related collection&#xD;
of objects – orderlines for instance – is empty when called. It just seems more logical&#xD;
with lazy loading.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
So instead you can now in EF4 decide to let the related objects load silently when&#xD;
they are called, resulting of course in further calls to the DB.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
The lazy load or deferred load option is set on the context, and is disabled by default:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    1&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;using&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;var&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;context&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;new&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;OrderModelContainer&lt;/span&gt;())&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    2&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    3&lt;/span&gt;     &lt;span style="color: #eee8aa"&gt;context&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ContextOptions&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;DeferredLoadingEnabled&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;true&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    4&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    5&lt;/span&gt;     &lt;span style="color: #eee8aa"&gt;var&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;orders&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;from&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;o&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;in&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;context&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;OrderSet&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;select&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;o&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    6&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    7&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;var&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;order&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;in&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;orders&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    8&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    9&lt;/span&gt;         &lt;span style="color: #eee8aa"&gt;Console&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;WriteLine&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;order&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;CreatedDate&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   10&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #eee8aa"&gt;var&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;orderline&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;in&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;order&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;OrderLines&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   11&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   12&lt;/span&gt;             &lt;span style="color: #eee8aa"&gt;Console&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;WriteLine&lt;/span&gt;(&lt;span style="color: #60ff60"&gt;" &#xD;
"&lt;/span&gt;&lt;span style="color: silver"&gt;+&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;orderline&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Quantity&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   13&lt;/span&gt;                         &lt;span style="color: silver"&gt;+&lt;/span&gt;&lt;span style="color: #60ff60"&gt;"&#xD;
"&lt;/span&gt;&lt;span style="color: silver"&gt;+&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;orderline&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Product&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Name&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   14&lt;/span&gt;                         &lt;span style="color: silver"&gt;+&lt;/span&gt;&lt;span style="color: #60ff60"&gt;"&#xD;
of $"&lt;/span&gt;&lt;span style="color: silver"&gt;+&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;orderline&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ItemPrice&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   15&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   16&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   17&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
Both the eager loaded and the lazy loaded produces the following result:&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://devtalk.dk/content/binary/WindowsLiveWriter/Ent.0Beta1POCOLazyloadandcodegenerationo_343/image_26.png"&gt;&#xD;
            &lt;img style="border-bottom: 0px; border-left: 0px; margin: 0px 0px 0px 20px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://devtalk.dk/content/binary/WindowsLiveWriter/Ent.0Beta1POCOLazyloadandcodegenerationo_343/image_thumb_12.png" width="400" height="272"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Setting the lazy load on the context seems very limited, and it would be much more&#xD;
helpful to the developer in a real world scenario if you could define the load strategy&#xD;
per navigation property. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
The best that i can see as an option is that you enable lazy loading, and then handle&#xD;
the cases you know are going to do a lot of DB roundtrips with eager loading and do&#xD;
a sort of combo. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
All in all i still think that EF4 is gigantic leap forward, and so far it has been&#xD;
surprisingly easy to make everything run as expected.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;strong&gt;Resources&lt;/strong&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;ul&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://devtalk.dk/content/binary/EF4BetaLazyLoad.rar"&gt;Download the source&#xD;
for the post&lt;/a&gt;&#xD;
          &lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://blogs.msdn.com/adonet/default.aspx"&gt;ADO.Net Team Blog&lt;/a&gt;&#xD;
          &lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/adonetefx/threads"&gt;Pre EF4&#xD;
Forum&lt;/a&gt;&#xD;
          &lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://msdn.microsoft.com/en-us/library/bb399572(VS.100).aspx"&gt;Documentation&lt;/a&gt;&#xD;
          &lt;/li&gt;&#xD;
        &lt;/ul&gt;&#xD;
        &lt;img width="0" height="0" src="http://devtalk.dk/aggbug.ashx?id=70735551-fa79-472f-831b-9744596fbfa9"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=oX7sXYTkp0k:41nSY27oEA4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=oX7sXYTkp0k:41nSY27oEA4:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=oX7sXYTkp0k:41nSY27oEA4:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=oX7sXYTkp0k:41nSY27oEA4:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=oX7sXYTkp0k:41nSY27oEA4:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=oX7sXYTkp0k:41nSY27oEA4:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=oX7sXYTkp0k:41nSY27oEA4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=oX7sXYTkp0k:41nSY27oEA4:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=oX7sXYTkp0k:41nSY27oEA4:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevtalknetBlog/~4/oX7sXYTkp0k" height="1" width="1"/&gt;</description>
      <comments>http://devtalk.dk/CommentView,guid,70735551-fa79-472f-831b-9744596fbfa9.aspx</comments>
      <category>EF4</category>
      <category>Entity Framework</category>
    <feedburner:origLink>http://devtalk.dk/2009/05/26/Entity+Framework+40+Beta+1+POCO+Lazy+Load+And+Code+Generation+Of+ObjectContext.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://devtalk.dk/Trackback.aspx?guid=d51e3a7d-6d80-4c5c-84ad-2a4587316a2e</trackback:ping>
      <pingback:server>http://devtalk.dk/pingback.aspx</pingback:server>
      <pingback:target>http://devtalk.dk/PermaLink,guid,d51e3a7d-6d80-4c5c-84ad-2a4587316a2e.aspx</pingback:target>
      <dc:creator>Joachim Lykke Andersen</dc:creator>
      <wfw:comment>http://devtalk.dk/CommentView,guid,d51e3a7d-6d80-4c5c-84ad-2a4587316a2e.aspx</wfw:comment>
      <wfw:commentRss>http://devtalk.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=d51e3a7d-6d80-4c5c-84ad-2a4587316a2e</wfw:commentRss>
      <slash:comments>1</slash:comments>
      
      <title>Entity Framework 4.0 – How To POCO</title>
      <guid isPermaLink="false">http://devtalk.dk/PermaLink,guid,d51e3a7d-6d80-4c5c-84ad-2a4587316a2e.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevtalknetBlog/~3/E31qxsu7JAc/Entity+Framework+40+How+To+POCO.aspx</link>
      <pubDate>Fri, 22 May 2009 23:32:35 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
I have been looking forward to this for a while, and tonight i finally got around&#xD;
to installing Visual Studio 2010 and .Net 4.0 Beta 1 – including the new Entity Framework&#xD;
bits.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
You may remember that i was &lt;a href="http://www.anug.dk/post/2008/09/17/Joachim-Lykke-Andersen-om-Entity-Framework-10.aspx"&gt;not&#xD;
completely sold on Entity Framework 1.0&lt;/a&gt;, and &lt;a href="http://efvote.wufoo.com/forms/ado-net-entity-framework-vote-of-no-confidence/"&gt;neither&#xD;
was a big part of the developer community&lt;/a&gt;, so there are of course a lot of areas&#xD;
that I am really looking forward to explore in this coming version of the framework.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
First and foremost I was very curious as to whether the Entity Framwork offers the&#xD;
promised POCO scenario, so as a first encounter I set of to figure out if this is&#xD;
the case or not.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
I started out with creating a solution with only one project called “Model” containing&#xD;
a single class “Customer”:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 12pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    6&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;namespace&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;EntityFrameworkPoco&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Model&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    7&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    8&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;class&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;Customer&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;    9&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   10&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;int&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Id&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   11&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;string&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;FirstName&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   12&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;string&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;LastName&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   13&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;int&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Age&lt;/span&gt; { &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;; &lt;span style="color: #40c4ff"&gt;set&lt;/span&gt;;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   14&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   15&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
So now I have defined a simple Poco class that i want to use with the Entity Framework.&#xD;
I am not going to change this class in any way.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Next step is to create the model. I can create the metadata files myself or I can&#xD;
use the designer. I dont have a database with customers, and as I want to test another&#xD;
feature of the new Entity Framework I go with the designer:&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
So I create another project that I call EntityFramework, and to that i add a new ADO.Net&#xD;
Entity Data Model.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://devtalk.dk/content/binary/WindowsLiveWriter/EntityFramework4.0HowToPOCO_14524/image_4.png"&gt;&#xD;
            &lt;img style="border-right-width: 0px; margin: 0px 0px 0px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://devtalk.dk/content/binary/WindowsLiveWriter/EntityFramework4.0HowToPOCO_14524/image_thumb_1.png" width="400" height="277"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
I select the .edmx file in the solution explorer, and in the Entity Framework Designer&#xD;
interface i create my Customer entity replicating my actual POCO entity, and as i&#xD;
dont have a database for my customers i right click and choose “Generate Database&#xD;
Script from Model”. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://devtalk.dk/content/binary/WindowsLiveWriter/EntityFramework4.0HowToPOCO_14524/image_2.png"&gt;&#xD;
            &lt;img style="border-right-width: 0px; margin: 0px 0px 0px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://devtalk.dk/content/binary/WindowsLiveWriter/EntityFramework4.0HowToPOCO_14524/image_thumb.png" width="400" height="345"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
I choose my database connection and let it create a new database for me. The dialog&#xD;
then generates the SQL script needed to create the model in my database. Neat. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://devtalk.dk/content/binary/WindowsLiveWriter/EntityFramework4.0HowToPOCO_14524/image_6.png"&gt;&#xD;
            &lt;img style="border-right-width: 0px; margin: 0px 0px 0px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://devtalk.dk/content/binary/WindowsLiveWriter/EntityFramework4.0HowToPOCO_14524/image_thumb_2.png" width="400" height="357"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
So now I have plugged in the EF to allow me to persist my POCO object to database,&#xD;
and materialize it back to me. One thing we need to remember is, that we don’t want&#xD;
the Entity Data Model we just created, to generate code for us – we want to handle&#xD;
that ourselves – well at least for now.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://devtalk.dk/content/binary/WindowsLiveWriter/EntityFramework4.0HowToPOCO_14524/image_8.png"&gt;&#xD;
            &lt;img style="border-right-width: 0px; margin: 0px 0px 0px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://devtalk.dk/content/binary/WindowsLiveWriter/EntityFramework4.0HowToPOCO_14524/image_thumb_3.png" width="400" height="300"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;  &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Therefore we remove the “Custom Tool” that generates the code. Just delete the content&#xD;
of the property. This turns of code generation for the model.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
So far so good. Now we need to hook it all up. We are going to need a context implementation&#xD;
now that it is not generated for us. So lets create the the CustomerContext on our&#xD;
EntityFramework project and let it expose a collection of our POCO Customers – an&#xD;
ObjectSet of Customer that is:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 12pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   10&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;class&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;CustomerContext&lt;/span&gt; : &lt;span style="color: #66cdaa"&gt;ObjectContext&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   11&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   12&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;private&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;ObjectSet&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;Customer&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;_customers&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   13&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   14&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;CustomerContext&lt;/span&gt;(): &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   15&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;base&lt;/span&gt;(&lt;span style="color: #60ff60"&gt;"name=CustomerModelContainer"&lt;/span&gt;, &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   16&lt;/span&gt;              &lt;span style="color: #60ff60"&gt;"CustomerModelContainer"&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   17&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   18&lt;/span&gt;         &lt;span style="color: #eee8aa"&gt;_customers&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   19&lt;/span&gt;             &lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;CreateObjectSet&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;Customer&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   20&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   21&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   22&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;ObjectSet&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;Customer&lt;/span&gt;&lt;span style="color: silver"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Customers&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   23&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   24&lt;/span&gt;         &lt;span style="color: #40c4ff"&gt;get&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   25&lt;/span&gt;        &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   26&lt;/span&gt;             &lt;span style="color: #40c4ff"&gt;return&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;_customers&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   27&lt;/span&gt;        &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   28&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   29&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   30&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
Too simple of course, but for now it will let us fetch customers from database. Behind&#xD;
the scenes i cheat and create a few in the database, so that we can test it.&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 12pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   36&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;static&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;void&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Main&lt;/span&gt;(&lt;span style="color: #40c4ff"&gt;string&lt;/span&gt;[] &lt;span style="color: #eee8aa"&gt;args&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   37&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   38&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;var&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;context&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;new&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;CustomerContext&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   39&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;var&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;customers&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;from&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;c&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;in&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;context&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Customers&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   40&lt;/span&gt;                     &lt;span style="color: #40c4ff"&gt;select&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;c&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   41&lt;/span&gt; &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   42&lt;/span&gt;     &lt;span style="color: #40c4ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #40c4ff"&gt;var&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;customer&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;in&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;customers&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   43&lt;/span&gt;    &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   44&lt;/span&gt;         &lt;span style="color: #66cdaa"&gt;Console&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;WriteLine&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;customer&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;FirstName&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   45&lt;/span&gt;    &#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   46&lt;/span&gt;     &lt;span style="color: #66cdaa"&gt;Console&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;ReadKey&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   47&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
Which results in the following output. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://devtalk.dk/content/binary/WindowsLiveWriter/EntityFramework4.0HowToPOCO_14524/image_10.png"&gt;&#xD;
            &lt;img style="border-right-width: 0px; margin: 0px 0px 0px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://devtalk.dk/content/binary/WindowsLiveWriter/EntityFramework4.0HowToPOCO_14524/image_thumb_4.png" width="240" height="152"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Now if we want to add new customers we could add a method to our context like so:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 12pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   50&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;public&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;void&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;AddCustomer&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;Customer&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;customer&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   51&lt;/span&gt; {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   52&lt;/span&gt;     &lt;span style="color: #eee8aa"&gt;_customers&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;AddObject&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;customer&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   53&lt;/span&gt; }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
Which enables us to add a new customer:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: consolas; background: #171717; color: #e0e0e0; font-size: 12pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   41&lt;/span&gt; &lt;span style="color: #40c4ff"&gt;var&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;newCustomer&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #40c4ff"&gt;new&lt;/span&gt;&lt;span style="color: #66cdaa"&gt;Customer&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   42&lt;/span&gt; &lt;span style="color: #eee8aa"&gt;newCustomer&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;FirstName&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #60ff60"&gt;"Jim"&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   43&lt;/span&gt; &lt;span style="color: #eee8aa"&gt;newCustomer&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;LastName&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #60ff60"&gt;"Test"&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   44&lt;/span&gt; &lt;span style="color: #eee8aa"&gt;newCustomer&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;Age&lt;/span&gt;&lt;span style="color: silver"&gt;=&lt;/span&gt;&lt;span style="color: #60ff60"&gt;42&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   45&lt;/span&gt; &lt;span style="color: #eee8aa"&gt;context&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;AddCustomer&lt;/span&gt;(&lt;span style="color: #eee8aa"&gt;newCustomer&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="background: #404040; color: #adadad"&gt;   46&lt;/span&gt; &lt;span style="color: #eee8aa"&gt;context&lt;/span&gt;&lt;span style="color: silver"&gt;.&lt;/span&gt;&lt;span style="color: #eee8aa"&gt;SaveChanges&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
This is of course a very superficial example of POCO with the entity framework, but&#xD;
it is indeed very promising. I will be looking further into some more advanced examples&#xD;
in the near future.&#xD;
&lt;/p&gt;&#xD;
        &lt;img width="0" height="0" src="http://devtalk.dk/aggbug.ashx?id=d51e3a7d-6d80-4c5c-84ad-2a4587316a2e"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=E31qxsu7JAc:j4P9MDI4DRE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=E31qxsu7JAc:j4P9MDI4DRE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=E31qxsu7JAc:j4P9MDI4DRE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=E31qxsu7JAc:j4P9MDI4DRE:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=E31qxsu7JAc:j4P9MDI4DRE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=E31qxsu7JAc:j4P9MDI4DRE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=E31qxsu7JAc:j4P9MDI4DRE:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=E31qxsu7JAc:j4P9MDI4DRE:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=E31qxsu7JAc:j4P9MDI4DRE:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevtalknetBlog/~4/E31qxsu7JAc" height="1" width="1"/&gt;</description>
      <comments>http://devtalk.dk/CommentView,guid,d51e3a7d-6d80-4c5c-84ad-2a4587316a2e.aspx</comments>
      <category>EF4</category>
      <category>Entity Framework</category>
    <feedburner:origLink>http://devtalk.dk/2009/05/22/Entity+Framework+40+How+To+POCO.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://devtalk.dk/Trackback.aspx?guid=162cc061-7742-4f06-8c63-b12e8548b723</trackback:ping>
      <pingback:server>http://devtalk.dk/pingback.aspx</pingback:server>
      <pingback:target>http://devtalk.dk/PermaLink,guid,162cc061-7742-4f06-8c63-b12e8548b723.aspx</pingback:target>
      <dc:creator>Joachim Lykke Andersen</dc:creator>
      <wfw:comment>http://devtalk.dk/CommentView,guid,162cc061-7742-4f06-8c63-b12e8548b723.aspx</wfw:comment>
      <wfw:commentRss>http://devtalk.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=162cc061-7742-4f06-8c63-b12e8548b723</wfw:commentRss>
      
      <title>MSDN Blogger of the Year – Please Vote</title>
      <guid isPermaLink="false">http://devtalk.dk/PermaLink,guid,162cc061-7742-4f06-8c63-b12e8548b723.aspx</guid>
      <link>http://feedproxy.google.com/~r/DevtalknetBlog/~3/P4CQm4tbj3c/MSDN+Blogger+Of+The+Year+Please+Vote.aspx</link>
      <pubDate>Sun, 14 Dec 2008 20:33:43 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
In the latest &lt;a href="http://www.microsoft.com/danmark/msdn/nyhedsbrev.mspx"&gt;MSDN&#xD;
Flash newsletter&lt;/a&gt; candidates are wanted for Blogger of the Year for 2008. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
So please vote for your favorite blog by writing an email to &lt;a href="mailto:dorthelk@microsoft.com"&gt;dorthelk@microsoft.com&lt;/a&gt; with&#xD;
the name of the blog and blogger you think deserves the title of the best blog of&#xD;
the year.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
If you have enjoyed posts on my blog I would be very grateful for your vote ;)&#xD;
&lt;/p&gt;&#xD;
        &lt;img width="0" height="0" src="http://devtalk.dk/aggbug.ashx?id=162cc061-7742-4f06-8c63-b12e8548b723"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=P4CQm4tbj3c:Wg0Lk7aMzPU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=P4CQm4tbj3c:Wg0Lk7aMzPU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=P4CQm4tbj3c:Wg0Lk7aMzPU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=P4CQm4tbj3c:Wg0Lk7aMzPU:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=P4CQm4tbj3c:Wg0Lk7aMzPU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=P4CQm4tbj3c:Wg0Lk7aMzPU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=P4CQm4tbj3c:Wg0Lk7aMzPU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/DevtalknetBlog?a=P4CQm4tbj3c:Wg0Lk7aMzPU:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DevtalknetBlog?i=P4CQm4tbj3c:Wg0Lk7aMzPU:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DevtalknetBlog/~4/P4CQm4tbj3c" height="1" width="1"/&gt;</description>
      <comments>http://devtalk.dk/CommentView,guid,162cc061-7742-4f06-8c63-b12e8548b723.aspx</comments>
    <feedburner:origLink>http://devtalk.dk/2008/12/14/MSDN+Blogger+Of+The+Year+Please+Vote.aspx</feedburner:origLink></item>
  </channel>
</rss>

