<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Jaroslaw Kowalski</title><subtitle type="html" /><id>http://blogs.msdn.com/jkowalski/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jkowalski/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/jkowalski/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2008-05-28T09:11:00Z</updated><entry><title>Using EFProviderWrappers with precompiled views</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jkowalski/archive/2009/06/15/using-efproviderwrappers-with-precompiled-views.aspx" /><id>http://blogs.msdn.com/jkowalski/archive/2009/06/15/using-efproviderwrappers-with-precompiled-views.aspx</id><published>2009-06-15T19:06:54Z</published><updated>2009-06-15T19:06:54Z</updated><content type="html">&lt;p&gt;One of the users has reported a problem with using &lt;a href="http://code.msdn.com/EFProviderWrappers"&gt;EFProviderWrappers&lt;/a&gt; and precompiled views together.&lt;/p&gt;  &lt;p&gt;When you pre-compile views, Entity Framework calculates a hash of metadata (which includes csdl,ssdl and msl information), stores it with the generated views and compares it later when metadata is loaded. When loaded metadata doesn’t match the hash stored in pre-compiled views, an exception is thrown.&lt;/p&gt;  &lt;p&gt;Injecting a provider into provider chains involves changing SSDL file and that invalidates the hash.&lt;/p&gt;  &lt;p&gt;Fortunately there’s a workaround, which enables you to use pre-compiled views and wrapper providers together, but you have to use the &lt;a href="http://blogs.msdn.com/jkowalski/archive/2009/06/11/tracing-and-caching-in-entity-framework-available-on-msdn-code-gallery.aspx#alternativeinjection"&gt;Alternative injection method as described in original blog post&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Let’s assume you have followed the steps outlined in the post and have your modified SSDL file ready. Injecting is a bit tricky because of additional registration required for EdmGen.exe to work. The first part involves creating a modified version of EdmGen.exe which can handle wrapper providers:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Create a working directory (say “&lt;strong&gt;C:\ViewGeneration&lt;/strong&gt;”) &lt;/li&gt;    &lt;li&gt;Copy &lt;strong&gt;%WINDIR%\Microsoft.NET\Framework\v3.5\EdmGen.exe&lt;/strong&gt; and &lt;strong&gt;%WINDIR%\Microsoft.NET\Framework\v3.5\EdmGen.exe.config&lt;/strong&gt; to that directory &lt;/li&gt;    &lt;li&gt;Open &lt;strong&gt;C:\ViewGeneration\EdmGen.exe.config&lt;/strong&gt; using notepad &lt;/li&gt;    &lt;li&gt;Add Provider Registration section before the end of the configuration file so that it looks like this:      &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;encoding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt; ?&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;runtime&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;generatePublisherEvidence&lt;/span&gt; &lt;span class="attr"&gt;enabled&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;runtime&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="rem"&gt;&amp;lt;!-- declare provider factories --&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.data&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;DbProviderFactories&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;EF Caching Data Provider&amp;quot;&lt;/span&gt;
           &lt;span class="attr"&gt;invariant&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;EFCachingProvider&amp;quot;&lt;/span&gt;
           &lt;span class="attr"&gt;description&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Caching Provider Wrapper&amp;quot;&lt;/span&gt;
           &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;EFCachingProvider.EFCachingProviderFactory, EFCachingProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=def642f226e0e59b&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;EF Tracing Data Provider&amp;quot;&lt;/span&gt;
           &lt;span class="attr"&gt;invariant&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;EFTracingProvider&amp;quot;&lt;/span&gt;
           &lt;span class="attr"&gt;description&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Tracing Provider Wrapper&amp;quot;&lt;/span&gt;
           &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;EFTracingProvider.EFTracingProviderFactory, EFTracingProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=def642f226e0e59b&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;EF Generic Provider Wrapper&amp;quot;&lt;/span&gt;
           &lt;span class="attr"&gt;invariant&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;EFProviderWrapper&amp;quot;&lt;/span&gt;
           &lt;span class="attr"&gt;description&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Generic Provider Wrapper&amp;quot;&lt;/span&gt;
           &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;EFProviderWrapperToolkit.EFProviderWrapperFactory, EFProviderWrapperToolkit, Version=1.0.0.0, Culture=neutral, PublicKeyToken=def642f226e0e59b&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;DbProviderFactories&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;system.data&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
  &lt;/li&gt;

  &lt;li&gt;Copy &lt;strong&gt;EFTracingProvider.dll, EFCachingProvider.dll&lt;/strong&gt; and &lt;strong&gt;EFProviderWrapperToolkit.dll&lt;/strong&gt; to &lt;strong&gt;C:\ViewGeneration&lt;/strong&gt; &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;(Alternatively you can just gac all the providers and put provider registration section in machine.config, but I think the described method is cleaner as it has only local impact and doesn’t require you to be an administrator).&lt;/p&gt;

&lt;p&gt;Once you have the modified EdmGen.exe, you can use it for your view generation as usual, except that you pass modified ssdl file as an argument to /inssdl parameter.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;C:\ViewGeneration\EdmGen.exe 
    /mode:viewgeneration 
    /incsdl:NorthwindEFModel.csdl 
    /inssdl:NorthwindEFModel.WithTracing.ssdl 
    /inmsl:NorthwindEFModel.msl 
    /outviews:NorthwindEF.views.cs&lt;/pre&gt;

&lt;p&gt;This should create you NorthwindEF.views.cs which you can compile along with the rest of your application to get better startup performance.&lt;/p&gt;

&lt;p&gt;Now, one more cool trick:&lt;/p&gt;

&lt;p&gt;Wrapper-enabled EdmGen.exe can be used not just for view generation. For example it is possible to automatically generate a model from a database using EFTracingProvider! (this will create SSDL file which takes advantage of tracing automatically).&lt;/p&gt;

&lt;pre class="csharpcode"&gt;C:\ViewGeneration\EdmGen.exe 
    /mode:FullGeneration
    /provider:EFTracingProvider
    /connectionString:&lt;span class="str"&gt;&amp;quot;wrappedProvider=System.Data.SqlClient;server=.\SQLEXPRESS;database=NorthwindEF;integrated security=sspi&amp;quot;&lt;/span&gt; /project:NW&lt;/pre&gt;

&lt;p&gt;You can even use tracing provider &lt;u&gt;during&lt;/u&gt; reverse-engineering process, to see what SQL statements are executed. All you need to do is add this section to &lt;strong&gt;C:\ViewGeneration\EdmGen.exe.config&lt;/strong&gt;:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="rem"&gt;&amp;lt;!-- this setting causes all log messages to be written to the console. --&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;EFTracingProvider.logToConsole&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9753672" width="1" height="1"&gt;</content><author><name>jkowalski</name><uri>http://blogs.msdn.com/members/jkowalski.aspx</uri></author><category term="Entity Framework" scheme="http://blogs.msdn.com/jkowalski/archive/tags/Entity+Framework/default.aspx" /><category term="Caching" scheme="http://blogs.msdn.com/jkowalski/archive/tags/Caching/default.aspx" /><category term="EFProviderWrappers" scheme="http://blogs.msdn.com/jkowalski/archive/tags/EFProviderWrappers/default.aspx" /><category term="Providers" scheme="http://blogs.msdn.com/jkowalski/archive/tags/Providers/default.aspx" /></entry><entry><title>Tracing and Caching for Entity Framework available on MSDN Code Gallery</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jkowalski/archive/2009/06/11/tracing-and-caching-in-entity-framework-available-on-msdn-code-gallery.aspx" /><id>http://blogs.msdn.com/jkowalski/archive/2009/06/11/tracing-and-caching-in-entity-framework-available-on-msdn-code-gallery.aspx</id><published>2009-06-11T20:29:00Z</published><updated>2009-06-11T20:29:00Z</updated><content type="html">&lt;P&gt;We have just &lt;A href="http://code.msdn.com/EFProviderWrappers" mce_href="http://code.msdn.com/EFProviderWrappers"&gt;released a sample&lt;/A&gt; that shows how to extend Entity Framework in interesting ways by plugging into ADO.NET provider interface. The sample provides two extensions:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;STRONG&gt;EFTracingProvider&lt;/STRONG&gt; – which adds the ability to log all SQL commands that are executed (similar to LINQ to SQL’s DataContext.Log&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;STRONG&gt;EFCachingProvider&lt;/STRONG&gt; – which adds transparent query results cache to EF &lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;The sample comes with implementation of distributed cache which uses &lt;A href="http://blogs.msdn.com/velocity/archive/2009/04/08/announcing-velocity-ctp3.aspx" mce_href="http://blogs.msdn.com/velocity/archive/2009/04/08/announcing-velocity-ctp3.aspx"&gt;Velocity CTP 3&lt;/A&gt; as well as an adapter for ASP.NET and simple in-memory cache implementation.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Because the sample is quite large and uses many advanced techniques, it’s impossible to fully explain it all in one blog post. In this first post I’ll briefly explain the idea of wrapper providers and describe the new the APIs exposed by EFTracingProvider and EFCachingProvider. In future posts I’ll try to explain more technical detail details and provide advanced logging/caching tips.&lt;/SPAN&gt;&lt;/P&gt;
&lt;H3&gt;Provider Wrapers&lt;/H3&gt;
&lt;P&gt;Entity Framework has a public provider model which makes it possible for provider writers to support 3&lt;SUP&gt;rd&lt;/SUP&gt;-party databases, such as Oracle, MySQL, PostreSQL, Firebird. The provider model provides uniform way for EF to query the capabilities of the database and execute queries and updates using canonical query tree representation (as opposed to textual queries).&lt;/P&gt;
&lt;P&gt;Whenever you issue a LINQ or Entity SQL query through an ObjectContext instance, the query passes through a series of layers (see the picture below). At high level we can say that all queries and updates from ObjectContext are translated and executed through EntityConnection, which in turns talks to server-specific data provider such as SqlClient or Sql Server CE client. &lt;/P&gt;
&lt;P&gt;Provider interface used by Entity Framework is stackable, which means it’s possible to write a provider which will wrap another provider and intercept communication between Entity Framework and the original provider. &lt;/P&gt;
&lt;P&gt;The wrapper provider gets a chance do interesting things, such as:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Examining query trees and commands before they are executed &lt;/LI&gt;
&lt;LI&gt;Controlling connections, commands, transactions, data readers, etc. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/jkowalski/WindowsLiveWriter/TracingandCachinginEntityFrameworkavaila_860F/image_3.png" width=528 height=408 mce_src="http://blogs.msdn.com/blogfiles/jkowalski/WindowsLiveWriter/TracingandCachinginEntityFrameworkavaila_860F/image_3.png"&gt; &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;EFTracingProvider&lt;/STRONG&gt; intercepts DbCommand.ExecuteReader(), ExecuteScalar() and ExecuteNonQuery() and sends details about the command (including command text and parameters) to configured outputs.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;EFCachingProvider&lt;/STRONG&gt; is a bit more complex. It uses external caching implementation and caches results of all queries queries that are executed in DbCommand.ExecuteReader(). Whenever update is detected (either UPDATE, INSERT or DELETE) the provider invalidates affected cache entries by evicting all cached queries which were dependent on any of the updated tables.&lt;/P&gt;
&lt;H3&gt;Using the sample code&lt;/H3&gt;
&lt;P&gt;Here’s a step-by-step guide to downloading and using the sample code in your project:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Download the sample project from MSDN Code Gallery and built it. &lt;/LI&gt;
&lt;LI&gt;Take &lt;B&gt;EFCachingProvider.dll&lt;/B&gt;, &lt;B&gt;EFTracingProvider.dll&lt;/B&gt; and &lt;B&gt;EFProviderWrapperToolkit.dll&lt;/B&gt; and place them in a common directory for easy referencing. &lt;/LI&gt;
&lt;LI&gt;Add reference to those three assemblies in your application. &lt;/LI&gt;
&lt;LI&gt;Register the providers – either: 
&lt;OL&gt;
&lt;LI&gt;Locally for your application (recommended) – put registration entries in App.config (see Provider Registration section below) and make sure that provider DLLs are in your application directory (adding reference and building should take care of that). &lt;/LI&gt;
&lt;LI&gt;Globally: GAC the providers and add required registration entries (see Provider Registration section below) to machine.config &lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;
&lt;LI&gt;Copy &lt;B&gt;EFProviderWrapperDemo\ExtendedNorthwindEntities.cs&lt;/B&gt; from the sample and put it in your project – rename the class as appropriate – you will need to use this class instead of a regular strongly typed object context class. &lt;/LI&gt;
&lt;LI&gt;Modify the base class by replacing NorthwindEntities with the name of your strongly typed object context class. &lt;/LI&gt;
&lt;LI&gt;Modify the default constructor by providing your own connection string. &lt;/LI&gt;
&lt;LI&gt;(optional) You can also modify the second constructor by specifying which wrapper providers to use. &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;That’s it. &lt;/P&gt;
&lt;H3&gt;Caching and Tracing APIs&lt;/H3&gt;
&lt;P&gt;By using &lt;B&gt;ExtendedNorthwindEntities&lt;/B&gt; which was created in previous step, instead of &lt;B&gt;NorthwindEntities&lt;/B&gt; you get access to new APIs which control caching and tracing:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; TextWriter Log { get; set; }&lt;/PRE&gt;
&lt;P&gt;Specifies the text writer where log output should be written - same as in LINQ to SQL &lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; ICache Cache { get; set; }&lt;/PRE&gt;
&lt;P&gt;Specifies which cache should be used for the context (typically a global one). The sample comes with 3 implementations of ICache interface which you can be used in your applications:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;AspNetCache – cache which uses ASP.NET caching mechanism &lt;/LI&gt;
&lt;LI&gt;InMemoryCache – simple, in-memory cache with basic LRU expiration policy &lt;/LI&gt;
&lt;LI&gt;VelocityCache – implementation of caching which uses Microsoft Distributed Cache codename "Velocity" CTP3. &lt;/LI&gt;&lt;/UL&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; CachingPolicy CachingPolicy { get; set; }&lt;/PRE&gt;
&lt;P&gt;Specifies caching policy. There are 3 policies included in the package:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;CachingPolicy.CacheAll – caches all queries regardless of their results size or affected tables &lt;/LI&gt;
&lt;LI&gt;CachingPolicy.NoCaching – disables caching &lt;/LI&gt;
&lt;LI&gt;CustomCachingPolicy – includes user-configurable list of tables that should and should not be cached, as well as expiration times and result size limits. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;It is also possible to write your own caching policy by creating a class which derives from CachingPolicy and overriding a bunch of methods.&lt;/P&gt;
&lt;P&gt;For more advanced logging scenarios there are also 3 events, which provide access to raw DbCommand objects and some additional information:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;event&lt;/SPAN&gt; EventHandler&amp;lt;CommandExecutionEventArgs&amp;gt; CommandExecuting
&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;event&lt;/SPAN&gt; EventHandler&amp;lt;CommandExecutionEventArgs&amp;gt; CommandFinished
&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;event&lt;/SPAN&gt; EventHandler&amp;lt;CommandExecutionEventArgs&amp;gt; CommandFailed&lt;/PRE&gt;
&lt;P&gt;The events are raised before and after each command is executed. &lt;/P&gt;
&lt;H3&gt;Global configuration&lt;/H3&gt;
&lt;P&gt;You can also configure logging defaults through static properties of EFTracingProviderConfiguration class and they will apply to all new contexts:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;static&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;bool&lt;/SPAN&gt; LogToConsole { get; set; }&lt;/PRE&gt;
&lt;P&gt;Specifies whether every SQL command should be logged to the console. &lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;static&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; LogToFile { get; set; }&lt;/PRE&gt;
&lt;P&gt;Specifies global log file. &lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;static&lt;/SPAN&gt; Action&amp;lt;CommandExecutionEventArgs&amp;gt; LogAction { get; set; }&lt;/PRE&gt;
&lt;P&gt;Specifies global custom logging action – a delegate that will be invoked before and after each command is executed.&lt;/P&gt;
&lt;H3&gt;Tracing Example&lt;/H3&gt;
&lt;P&gt;In order to write all SQL commands to a file, you must create a text writer object to write to and assign it to context.Log:&lt;/P&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; (TextWriter logFile = File.CreateText(&lt;SPAN class=str&gt;"sqllogfile.txt"&lt;/SPAN&gt;))
{
  &lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; (var context = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; ExtendedNorthwindEntities())
  {
    context.Log = logFile;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=rem&gt;// ... &lt;/SPAN&gt;
  }
}&lt;/PRE&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P&gt;Logging to the console is even easier:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; (var context = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; ExtendedNorthwindEntities())
{
  context.Log = Console.Out;&amp;nbsp;&amp;nbsp; &lt;SPAN class=rem&gt;// ... &lt;/SPAN&gt;
}&lt;/PRE&gt;
&lt;P&gt;More advanced logging can be achieved by hooking up Command*events:&lt;/P&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; (var context = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; ExtendedNorthwindEntities())
{
  context.CommandExecuting += (sender, e) =&amp;gt;
  {
   Console.WriteLine(&lt;SPAN class=str&gt;"Command is executing: {0}"&lt;/SPAN&gt;, e.ToTraceString());
  };
  context.CommandFinished += (sender, e) =&amp;gt;
  {
    Console.WriteLine(&lt;SPAN class=str&gt;"Command has finished: {0}"&lt;/SPAN&gt;, e.ToTraceString());
  };&amp;nbsp;&amp;nbsp; &lt;SPAN class=rem&gt;// ... &lt;/SPAN&gt;
}&lt;/PRE&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P&gt;To enable tracing globally for all connections (to both console and a log file):&lt;/P&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;&lt;PRE class=csharpcode&gt;EFTracingProviderConfiguration.LogToConsole = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;
EFTracingProviderConfiguration.LogToFile = &lt;SPAN class=str&gt;"MyLogFile.txt"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;H3&gt;
&lt;H3&gt;Caching Example&lt;/H3&gt;&lt;/H3&gt;
&lt;P&gt;In order to use caching using InMemoryCache implementation, you must create global instances of your cache and caching policy objects:&lt;/P&gt;&lt;PRE class=csharpcode&gt;ICache cache = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; InMemoryCache(); 
CachingPolicy cachingPolicy = CachingPolicy.CacheAll;&lt;/PRE&gt;
&lt;P&gt;In order to use caching with Velocity CTP3, you must create DataCache object and pass it to VelocityCache constructor.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;static&lt;/SPAN&gt; ICache CreateVelocityCache(&lt;SPAN class=kwrd&gt;bool&lt;/SPAN&gt; useLocalCache)
{
  DataCacheServerEndpoint endpoint = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; DataCacheServerEndpoint(&lt;SPAN class=str&gt;"localhost"&lt;/SPAN&gt;, 22233, &lt;SPAN class=str&gt;"DistributedCacheService"&lt;/SPAN&gt;);
  DataCacheFactory fac = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; DataCacheFactory(&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; DataCacheServerEndpoint[] { endpoint }, useLocalCache, useLocalCache);

  &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; VelocityCache(fac.GetCache(&lt;SPAN class=str&gt;"Velocity"&lt;/SPAN&gt;));
}&lt;/PRE&gt;
&lt;P&gt;Now in order to use either of the caches we need to set up Cache and CachingPolicy properties on the context:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; (var context = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; ExtendedNorthwindEntities())
{
  &lt;SPAN class=rem&gt;// set up caching&lt;/SPAN&gt;
  context.Cache = cache;
  context.CachingPolicy = cachingPolicy;&amp;nbsp;&amp;nbsp; &lt;SPAN class=rem&gt;// ... &lt;/SPAN&gt;
}&lt;/PRE&gt;
&lt;H3&gt;Configuring Providers&lt;/H3&gt;
&lt;H5&gt;Provider Registration&lt;/H5&gt;
&lt;P&gt;Before a provider can work with Entity Framework it must be registered, either in machine.config file or in application configuration file. Configuration for each provider specifies the factory class and gives it three names, two of which are human-readable name and one - provider invariant name is used to refer to the provider in the connection string and SSDL.&lt;/P&gt;
&lt;P&gt;Configuration for the providers included in the sample looks like this:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.data&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;DbProviderFactories&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;add&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="EF Caching Data Provider"&lt;/SPAN&gt;
         &lt;SPAN class=attr&gt;invariant&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="EFCachingProvider"&lt;/SPAN&gt;
         &lt;SPAN class=attr&gt;description&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Caching Provider Wrapper"&lt;/SPAN&gt;
         &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="EFCachingProvider.EFCachingProviderFactory, EFCachingProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=def642f226e0e59b"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;add&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="EF Tracing Data Provider"&lt;/SPAN&gt;
         &lt;SPAN class=attr&gt;invariant&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="EFTracingProvider"&lt;/SPAN&gt;
         &lt;SPAN class=attr&gt;description&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Tracing Provider Wrapper"&lt;/SPAN&gt;
         &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="EFTracingProvider.EFTracingProviderFactory, EFTracingProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=def642f226e0e59b"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;add&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="EF Generic Provider Wrapper"&lt;/SPAN&gt;
         &lt;SPAN class=attr&gt;invariant&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="EFProviderWrapper"&lt;/SPAN&gt;
         &lt;SPAN class=attr&gt;description&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Generic Provider Wrapper"&lt;/SPAN&gt;
         &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="EFProviderWrapperToolkit.EFProviderWrapperFactory, EFProviderWrapperToolkit, Version=1.0.0.0, Culture=neutral, PublicKeyToken=def642f226e0e59b"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;DbProviderFactories&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.data&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This XML fragment can be copied/pasted into any project which needs to use EF provider wrappers or put in the machine.config to be shared by all applications.&lt;/P&gt;
&lt;H3&gt;Injecting into provider chain&lt;/H3&gt;
&lt;P&gt;In order to inject the provider into the provider chain, you have to modify SSDL files for your project as well as the connection string. There are two ways to do so: automated (which requires application code changes) or manual which can be done externally just by changing configuration file and SSDL file.&lt;/P&gt;
&lt;P&gt;In order to create an EntityConnection with injected wrapped providers, you can use the provided helper method:&lt;/P&gt;&lt;PRE class=csharpcode&gt;connection = EntityConnectionWrapperUtils.CreateEntityConnectionWithWrappers(
  connectionString, &lt;SPAN class=str&gt;"EFTracingProvider"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"EFCachingProvider"&lt;/SPAN&gt;)&lt;/PRE&gt;
&lt;P&gt;You can then pass &lt;STRONG&gt;connection&lt;/STRONG&gt; to ObjectContext constructor or use the connection to run ESQL queries as usual. &lt;/P&gt;&lt;A title=alternativeinjection name=alternativeinjection&gt;&lt;/A&gt;
&lt;H3&gt;Alternative injection method&lt;/H3&gt;
&lt;P&gt;If you cannot change the application code, you have to make the modifications manually, which involves changing SSDL file and the connection string. Let’s take a quick look to see what SSDL and connection string look like today: The provider name is specified in the Provider attribute of the &amp;lt;Schema/&amp;gt; element:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Schema&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Namespace&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="NorthwindEFModel.Store"&lt;/SPAN&gt;
  &lt;SPAN class=attr&gt;Alias&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Self"&lt;/SPAN&gt;
  &lt;SPAN class=attr&gt;Provider&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="&lt;U&gt;&lt;STRONG&gt;&lt;FONT size=3&gt;System.Data.SqlClient&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/U&gt;"&lt;/SPAN&gt;
  &lt;SPAN class=attr&gt;ProviderManifestToken&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="&lt;STRONG&gt;&lt;U&gt;&lt;FONT size=3&gt;2005&lt;/FONT&gt;&lt;/U&gt;&lt;/STRONG&gt;"&lt;/SPAN&gt;
  &lt;SPAN class=attr&gt;xmlns&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://schemas.microsoft.com/ado/2006/04/edm/ssdl"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Provider invariant name is also be specified in the connection string:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;connectionStrings&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;add&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="NorthwindEntities"&lt;/SPAN&gt;
       &lt;SPAN class=attr&gt;connectionString&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="metadata=NorthwindEFModel.csdl | NorthwindEFModel.msl | NorthwindEFModel.ssdl;
                         provider=&lt;STRONG&gt;&lt;U&gt;&lt;FONT size=3&gt;System.Data.SqlClient&lt;/FONT&gt;&lt;/U&gt;&lt;/STRONG&gt;; 
                         provider connection string=&amp;amp;quot;Data Source=.\sqlexpress;
Initial Catalog=NorthwindEF;Integrated Security=True;MultipleActiveResultSets=True&amp;amp;quot;"&lt;/SPAN&gt;
       &lt;SPAN class=attr&gt;providerName&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="System.Data.EntityClient"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;connectionStrings&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;In order to inject our own provider we need to override those to point to our provider. In SSDL, we put the name of the new provider in the Provider attribute and concatenate the previous provider with its provider manifest token in the ProviderManifestToken field, like this:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;?&lt;/SPAN&gt;&lt;SPAN class=html&gt;xml&lt;/SPAN&gt; &lt;SPAN class=attr&gt;version&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="1.0"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;encoding&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="utf-8"&lt;/SPAN&gt;?&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Schema&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Namespace&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="NorthwindEFModel.Store"&lt;/SPAN&gt;
  &lt;SPAN class=attr&gt;Alias&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Self"&lt;/SPAN&gt;
  &lt;SPAN class=attr&gt;Provider&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="&lt;STRONG&gt;&lt;FONT size=3&gt;&lt;U&gt;EFCachingProvider&lt;/U&gt;&lt;/FONT&gt;&lt;/STRONG&gt;"&lt;/SPAN&gt;
  &lt;SPAN class=attr&gt;ProviderManifestToken&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="&lt;STRONG&gt;&lt;U&gt;&lt;FONT size=3&gt;System.Data.SqlClient;2005&lt;/FONT&gt;&lt;/U&gt;&lt;/STRONG&gt;"&lt;/SPAN&gt;
  &lt;SPAN class=attr&gt;xmlns&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://schemas.microsoft.com/ado/2006/04/edm/ssdl"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Modifying connection string is a bit different – we need to put the pointer to the new *.ssdl, change provider name and add new keyword to provider connection string:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;connectionStrings&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;add&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="NorthwindEntities"&lt;/SPAN&gt;
       &lt;SPAN class=attr&gt;connectionString&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="metadata=NorthwindEFModel.csdl | NorthwindEFModel.msl | &lt;STRONG&gt;&lt;U&gt;&lt;FONT size=3&gt;NorthwindEFModel.Modified.ssdl&lt;/FONT&gt;&lt;/U&gt;&lt;/STRONG&gt;;
                         provider=&lt;STRONG&gt;&lt;U&gt;&lt;FONT size=3&gt;EFCachingProvider&lt;/FONT&gt;&lt;/U&gt;&lt;/STRONG&gt;; 
                         provider connection string=&amp;amp;quot;&lt;U&gt;&lt;FONT size=3&gt;&lt;STRONG&gt;wrappedProvider=System.Data.SqlClient;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/U&gt;Data Source=.\sqlexpress;&lt;BR&gt;Initial Catalog=NorthwindEF;Integrated Security=True;MultipleActiveResultSets=True&amp;amp;quot;"&lt;/SPAN&gt;
       &lt;SPAN class=attr&gt;providerName&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="System.Data.EntityClient"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;connectionStrings&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;H5&gt;Specifying tracing configuration in the configuration file:&lt;/H5&gt;
&lt;P&gt;It is also possible to specify tracing configuration in App.config file. The following parameters are available:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;appSettings&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
  &lt;SPAN class=rem&gt;&amp;lt;!-- write log messages to the console. --&amp;gt;&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;add&lt;/SPAN&gt; &lt;SPAN class=attr&gt;key&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="EFTracingProvider.logToConsole"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;value&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="true"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    
  &lt;SPAN class=rem&gt;&amp;lt;!-- append log messages to the specified file --&amp;gt;&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;add&lt;/SPAN&gt; &lt;SPAN class=attr&gt;key&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="EFTracingProvider.logToFile"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;value&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="sqllog.txt"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;appSettings&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;H3&gt;Limitations and Disclaimers&lt;/H3&gt;
&lt;P&gt;The providers have not been extensively tested beyond what’s included in the sample code, so you should use tem at your own risk. &lt;/P&gt;
&lt;P&gt;As with any other sample, Microsoft is not offering any kind of support for it, but if you find bugs or have feature suggestions, please use this blog’s contact form and let me know about them.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9727163" width="1" height="1"&gt;</content><author><name>jkowalski</name><uri>http://blogs.msdn.com/members/jkowalski.aspx</uri></author><category term="Entity Framework" scheme="http://blogs.msdn.com/jkowalski/archive/tags/Entity+Framework/default.aspx" /><category term="Caching" scheme="http://blogs.msdn.com/jkowalski/archive/tags/Caching/default.aspx" /><category term="EFProviderWrappers" scheme="http://blogs.msdn.com/jkowalski/archive/tags/EFProviderWrappers/default.aspx" /><category term="Providers" scheme="http://blogs.msdn.com/jkowalski/archive/tags/Providers/default.aspx" /></entry><entry><title>Entity Framework samples converted to Visual Basic </title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jkowalski/archive/2009/05/21/entity-framework-samples-converted-to-visual-basic.aspx" /><id>http://blogs.msdn.com/jkowalski/archive/2009/05/21/entity-framework-samples-converted-to-visual-basic.aspx</id><published>2009-05-21T20:46:00Z</published><updated>2009-05-21T20:46:00Z</updated><content type="html">&lt;P&gt;We have recently published Visual Basic versions of our MSDN Code Gallery samples for Entity Framework v3.5SP1.&lt;/P&gt;
&lt;P&gt;The following translated samples are currently available in two languages (C# and VB)&lt;/P&gt;
&lt;P&gt;ADO.NET Entity Framework Query Samples&lt;BR&gt;&lt;A href="http://code.msdn.com/EFQuerySamples" mce_href="http://code.msdn.com/EFQuerySamples"&gt;http://code.msdn.com/EFQuerySamples&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Persistence Ignorance (POCO) Adapter for Entity Framework&lt;BR&gt;&lt;A href="http://code.msdn.com/EFPocoAdapter" mce_href="http://code.msdn.com/EFPocoAdapter"&gt;http://code.msdn.com/EFPocoAdapter&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Transparent Lazy Loading for Entity Framework&lt;BR&gt;&lt;A href="http://code.msdn.com/EFLazyLoading" mce_href="http://code.msdn.com/EFLazyLoading"&gt;http://code.msdn.com/EFLazyLoading&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The samples have been fully converted to use and generate Visual Basic&amp;nbsp;code instead of C#. More samples are in the pipeline and will be published soon - stay tuned. &lt;/P&gt;
&lt;P&gt;Full list of current EF samples published by the Entity Framework team is always available at:&lt;BR&gt;&lt;A href="http://code.msdn.microsoft.com/adonetefx" mce_href="http://code.msdn.microsoft.com/adonetefx"&gt;http://code.msdn.microsoft.com/adonetefx&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9634089" width="1" height="1"&gt;</content><author><name>jkowalski</name><uri>http://blogs.msdn.com/members/jkowalski.aspx</uri></author><category term="Entity Framework" scheme="http://blogs.msdn.com/jkowalski/archive/tags/Entity+Framework/default.aspx" /><category term="EFLazyLoading" scheme="http://blogs.msdn.com/jkowalski/archive/tags/EFLazyLoading/default.aspx" /><category term="EFPocoAdapter" scheme="http://blogs.msdn.com/jkowalski/archive/tags/EFPocoAdapter/default.aspx" /></entry><entry><title>New posts on EF Design Blog</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jkowalski/archive/2009/03/23/new-posts-on-ef-design-blog.aspx" /><id>http://blogs.msdn.com/jkowalski/archive/2009/03/23/new-posts-on-ef-design-blog.aspx</id><published>2009-03-24T05:42:04Z</published><updated>2009-03-24T05:42:04Z</updated><content type="html">&lt;p&gt;I’d like to turn your attention to two blog posts on &lt;a href="http://blogs.msdn.com/efdesign/"&gt;EF Design Blog&lt;/a&gt; about exciting new features planned for Entity Framework:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/efdesign/archive/2009/03/16/foreign-keys-in-the-entity-framework.aspx"&gt;Foreign Key Support&lt;/a&gt; – we’re introducing new type of association, which can be manipulated through references OR foreign key values available on entities themselves. We believe that this will greatly improve scenarios such as data binding, disconnected entities (N-Tier) and many others.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/efdesign/archive/2009/03/24/self-tracking-entities-in-the-entity-framework.aspx"&gt;Self-Tracking-Entities&lt;/a&gt; – it’s a simple way to have your entities track their state across tiers (based on custom code generation) and simple mechanism to save those changes to the database.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Your feedback is very important to us, please tell us what you think about those new features!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9503219" width="1" height="1"&gt;</content><author><name>jkowalski</name><uri>http://blogs.msdn.com/members/jkowalski.aspx</uri></author><category term="Entity Framework" scheme="http://blogs.msdn.com/jkowalski/archive/tags/Entity+Framework/default.aspx" /></entry><entry><title>N-Tier Improvements for Entity Framework</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jkowalski/archive/2008/11/20/n-tier-improvements-for-entity-framework.aspx" /><id>http://blogs.msdn.com/jkowalski/archive/2008/11/20/n-tier-improvements-for-entity-framework.aspx</id><published>2008-11-20T20:09:00Z</published><updated>2008-11-20T20:09:00Z</updated><content type="html">&lt;P&gt;We have recently published an article on API changes that we want to make in next version of Entity Framework in order to enable more N-Tier scenarios. Getting this right is very important to us and we're interested in getting as much of your feedback on the proposed design as possible. &lt;/P&gt;
&lt;P&gt;Please read and comment on the article at: &lt;A href="http://blogs.msdn.com/efdesign/archive/2008/11/20/n-tier-improvements-for-entity-framework.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/11/20/n-tier-improvements-for-entity-framework.aspx"&gt;http://blogs.msdn.com/efdesign/archive/2008/11/20/n-tier-improvements-for-entity-framework.aspx&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9129706" width="1" height="1"&gt;</content><author><name>jkowalski</name><uri>http://blogs.msdn.com/members/jkowalski.aspx</uri></author><category term="Entity Framework" scheme="http://blogs.msdn.com/jkowalski/archive/tags/Entity+Framework/default.aspx" /></entry><entry><title>Using EF Oracle Sample Provider with EDM Designer</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jkowalski/archive/2008/10/24/using-ef-oracle-sample-provider-with-edm-designer.aspx" /><id>http://blogs.msdn.com/jkowalski/archive/2008/10/24/using-ef-oracle-sample-provider-with-edm-designer.aspx</id><published>2008-10-24T20:24:49Z</published><updated>2008-10-24T20:24:49Z</updated><content type="html">&lt;p&gt;Many people are asking if it is possible to use &lt;a href="http://code.msdn.microsoft.com/EFOracleProvider"&gt;EFOracleProvider&lt;/a&gt; with EDM Designer in Visual Studio 2008 SP1. The answer is yes, but because the sample doesn't include a DDEX provider required for VS integration, there are certain steps that have to be run manually. &lt;/p&gt;  &lt;p&gt;I've compiled a step-by-step guide for those interested in trying this out (this assumes NorthwindEF sample database installed according to instructions included with the sample, but it should be straightforward to adjust it to your own setup)&lt;/p&gt;  &lt;h2&gt;PART 1 : INSTALLING ORACLE SAMPLE PROVIDER&lt;/h2&gt;  &lt;p&gt;1. Download and unzip EFOracleSampleProvider.zip from &lt;a href="http://code.msdn.com/EFOracleProvider"&gt;http://code.msdn.com/EFOracleProvider&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;2. Follow instructions in the README.txt to set up a sample database. &lt;/p&gt;  &lt;p&gt;3. Open elevated Visual Studio instance. Build the sample project. &lt;/p&gt;  &lt;p&gt;4. Open elevated command prompt and open machine.config using notepad:&amp;#160; &lt;br /&gt;&lt;strong&gt;notepad %WINDIR%\Microsoft.NET\Framework\v2.0.50727\config\machine.config&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;5. Find &amp;lt;DbProviderFactories&amp;gt; section and add EFOracleProvider entry:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;EF Oracle Data Provider&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;invariant&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;EFOracleProvider&amp;quot;&lt;/span&gt; 
     &lt;span class="attr"&gt;description&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;EF Provider for Oracle testing&amp;quot;&lt;/span&gt; 
     &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;EFOracleProvider.EFOracleProviderFactory, EFOracleProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=def642f226e0e59b&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;6. The completed system.data section has to look similar to this: &lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.data&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;DbProviderFactories&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Odbc Data Provider&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;invariant&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.Data.Odbc&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;description&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;.Net Framework Data Provider for Odbc&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.Data.Odbc.OdbcFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;OleDb Data Provider&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;invariant&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.Data.OleDb&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;description&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;.Net Framework Data Provider for OleDb&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.Data.OleDb.OleDbFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;OracleClient Data Provider&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;invariant&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.Data.OracleClient&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;description&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;.Net Framework Data Provider for Oracle&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.Data.OracleClient.OracleClientFactory, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;SqlClient Data Provider&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;invariant&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.Data.SqlClient&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;description&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;.Net Framework Data Provider for SqlServer&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;strong&gt;&lt;em&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;EF Oracle Data Provider&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;invariant&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;EFOracleProvider&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;description&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;EF Provider for Oracle testing&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;EFOracleProvider.EFOracleProviderFactory, EFOracleProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=def642f226e0e59b&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;/em&gt;&lt;/strong&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Microsoft SQL Server Compact Data Provider&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;invariant&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.Data.SqlServerCe.3.5&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;description&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;.NET Framework Data Provider for Microsoft SQL Server Compact&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;DbProviderFactories&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;system.data&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;h2&gt;PART 2: GENERATING MODEL FROM ORACLE DATABASE&lt;/h2&gt;

&lt;p&gt;7. Create a new project in VS. For simplicity let's create a console application&lt;/p&gt;

&lt;p&gt;8. Open elevated command prompt. Enter the directory that contains the newly created project and run the following command:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;%WINDIR%\Microsoft.NET\Framework\v3.5\edmgen.exe /provider:EFOracleProvider /mode:fullgeneration &lt;br /&gt;      /connectionstring:&lt;span class="str"&gt;&amp;quot;data source=XE;user id=edmuser;password=123456&amp;quot;&lt;/span&gt; /project:NorthwindEFModel&lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;The output should be:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Microsoft (R) EdmGen version 3.5.0.0
Copyright (C) 2008 Microsoft Corporation. All rights reserved.

Loading database information...
warning 6005: The data type &lt;span class="str"&gt;'timestamp(9)'&lt;/span&gt; is not supported, the column &lt;span class="str"&gt;'OrderDate'&lt;/span&gt; &lt;span class="kwrd"&gt;in&lt;/span&gt; table &lt;span class="str"&gt;'dbo.Orders'&lt;/span&gt; was excluded.
warning 6005: The data type &lt;span class="str"&gt;'timestamp(3)'&lt;/span&gt; is not supported, the column &lt;span class="str"&gt;'RequiredDate'&lt;/span&gt; &lt;span class="kwrd"&gt;in&lt;/span&gt; table &lt;span class="str"&gt;'dbo.Orders'&lt;/span&gt; was excluded.
Writing ssdl file...
Creating conceptual layer from storage layer...
Writing msl file...
Writing csdl file...
Writing object layer file...
Writing views file...

Generation Complete -- 0 errors, 2 warnings&lt;/pre&gt;

&lt;p&gt;9. This will create a bunch of NorthwindEFModel.* files for you.&lt;/p&gt;

&lt;p&gt;10. Open Northwind.ssdl file in a text editor and replace all instances of Schema=&amp;quot;dbo&amp;quot; with empty string (this is needed because tables in the sample Oracle database don't use a schema)&lt;/p&gt;

&lt;p&gt;11. In order to use generated model in the EF Ddesigner, we have to create NorthwindEFModel.edmx file. This can be done manually (just copy/paste contents of individual files into an empty EDMX as indicated by the comments) or by using &lt;a href="http://code.msdn.com/EdmGen2"&gt;EdmGen2 tool from Code Gallery&lt;/a&gt;:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;C:\Path\To\EdmGen2.exe /toedmx NorthwindEFModel.csdl NorthwindEFModel.ssdl NorthwindEFModel.msl&lt;/pre&gt;

&lt;p&gt;12. This will create NorthwindEFModel.edmx, which we can add to the project in VS. &lt;/p&gt;

&lt;p&gt;13. At this point you can now delete the following files generated by EdmGen.exe, which won't be necessary:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;NorthwindEFModel.csdl &lt;/li&gt;

  &lt;li&gt;NorthwindEFModel.ssdl &lt;/li&gt;

  &lt;li&gt;NorthwindEFModel.msl &lt;/li&gt;

  &lt;li&gt;NorthwindEFModel.ObjectLayer.cs &lt;/li&gt;

  &lt;li&gt;NorthwindEFModel.Views.cs &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;PART 3: TESTING GENERATED MODEL&lt;/h2&gt;

&lt;p&gt;14. The only remaining thing to do is to add App.config file with connection string for our Oracle database:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;encoding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt; ?&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;connectionStrings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;NorthwindEFModelContext&amp;quot;&lt;/span&gt; 
         &lt;span class="attr"&gt;connectionString&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;provider=EFOracleProvider;
                           metadata=res://*/NorthwindEFModel.csdl|res://*/NorthwindEFModel.ssdl|res://*/NorthwindEFModel.msl;
                           Provider Connection String='data source=XE;user id=edmuser;password=123456'&amp;quot;&lt;/span&gt; 
         &lt;span class="attr"&gt;providerName&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.Data.EntityClient&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;connectionStrings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;15. We can now try out our model by running a sample LINQ to Entities query:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; (NorthwindEFModelContext context = &lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindEFModelContext())
{
    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var c &lt;span class="kwrd"&gt;in&lt;/span&gt; context.Customers.Where(c=&amp;gt;c.City == &lt;span class="str"&gt;&amp;quot;Seattle&amp;quot;&lt;/span&gt;))
    {
        Console.WriteLine(c.CompanyName);
    }
}&lt;/pre&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9015021" width="1" height="1"&gt;</content><author><name>jkowalski</name><uri>http://blogs.msdn.com/members/jkowalski.aspx</uri></author><category term="Entity Framework" scheme="http://blogs.msdn.com/jkowalski/archive/tags/Entity+Framework/default.aspx" /><category term="EFSampleProvider" scheme="http://blogs.msdn.com/jkowalski/archive/tags/EFSampleProvider/default.aspx" /><category term="EFOracleProvider" scheme="http://blogs.msdn.com/jkowalski/archive/tags/EFOracleProvider/default.aspx" /></entry><entry><title>EF POCO Adapter updated (v1.03)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jkowalski/archive/2008/09/25/ef-poco-adapter-updated-v1-03.aspx" /><id>http://blogs.msdn.com/jkowalski/archive/2008/09/25/ef-poco-adapter-updated-v1-03.aspx</id><published>2008-09-26T06:24:05Z</published><updated>2008-09-26T06:24:05Z</updated><content type="html">&lt;p&gt;I've just posted another round of updates to EF POCO Adapter based on feedback from users. This set of changes is focused on N-tier scenarios and detached entities (it adds missing wrappers for EF APIs and fixes behavior of existing ones).&lt;/p&gt; &lt;p&gt;Change log:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Added wrapper for ObjectContext.ApplyPropertyChanges() to IEntitySet&amp;lt;T&amp;gt;  &lt;li&gt;Added wrapper for ObjectContext.Detach() to IEntitySet&amp;lt;T&amp;gt;  &lt;li&gt;Fixed handling of detached/out-of-scope entities w.r.t lazy loading and attaching to other contexts. Lazy loading outside of scope will do nothing if the context had DeferredLoadingEnabled=false, otherwise will throw.  &lt;li&gt;Added partial OnZZZCreated() methods on generated contexts, adapters and proxies to enable integration with 3rd-party extensions  &lt;li&gt;Fixed code generation from EDMX.  &lt;li&gt;EFPocoContext.EnableLazyLoading has been renamed to EFPocoContext.DeferredLoadingEnabled to better align with Linq to SQL and our plans for EF v2  &lt;li&gt;Fixed adapter-POCO synchronization for complex types&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;The new release is here: &lt;a href="http://code.msdn.microsoft.com/EFPocoAdapter/Release/ProjectReleases.aspx?ReleaseId=1580"&gt;http://code.msdn.microsoft.com/EFPocoAdapter/Release/ProjectReleases.aspx?ReleaseId=1580&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Big thanks to everyone who sent me comments, bug reports and improvement suggestions for this release. This is very valuable feedback as it allows us to better understand user scenarios around POCOs for EF v2.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8965874" width="1" height="1"&gt;</content><author><name>jkowalski</name><uri>http://blogs.msdn.com/members/jkowalski.aspx</uri></author><category term="Entity Framework" scheme="http://blogs.msdn.com/jkowalski/archive/tags/Entity+Framework/default.aspx" /><category term="EFPocoAdapter" scheme="http://blogs.msdn.com/jkowalski/archive/tags/EFPocoAdapter/default.aspx" /></entry><entry><title>EF POCO Adapter updated (v1.02)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jkowalski/archive/2008/09/13/ef-poco-adapter-updated-v1-02.aspx" /><id>http://blogs.msdn.com/jkowalski/archive/2008/09/13/ef-poco-adapter-updated-v1-02.aspx</id><published>2008-09-14T02:36:38Z</published><updated>2008-09-14T02:36:38Z</updated><content type="html">&lt;p&gt;I've just posted updates to EF POCO Adapter (v1.02) which resolves a couple of issues spotted by users:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Detached proxies (created by EFPocoContxt.CreateObject&amp;lt;T&amp;gt;) as well as proxies in the Added state were failing on property navigation. This has been fixed, and the property navigation doesn't attempt the load in one of these states. Thanks to &lt;a href="http://polymorphicview.blogspot.com/"&gt;Corey Gaudin&lt;/a&gt; for reporting this.&lt;/li&gt; &lt;li&gt;GetAdapterObject() was failing for proxies created with CreateObject&amp;lt;T&amp;gt;. This has been fixed by ensuring that adapters are always cached whenever proxies are present. As a side effect of this change, DetectChanges() should be a bit faster, as we don't have to walk object state manager anymore. Thanks to Corey Gaudin for reporting this.&lt;/li&gt; &lt;li&gt;Fixed code generator to eliminate compilation warning of unused property.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;The updated version is available &lt;a href="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=EFPocoAdapter&amp;amp;ReleaseId=1537"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8951316" width="1" height="1"&gt;</content><author><name>jkowalski</name><uri>http://blogs.msdn.com/members/jkowalski.aspx</uri></author><category term="Entity Framework" scheme="http://blogs.msdn.com/jkowalski/archive/tags/Entity+Framework/default.aspx" /><category term="EFPocoAdapter" scheme="http://blogs.msdn.com/jkowalski/archive/tags/EFPocoAdapter/default.aspx" /></entry><entry><title>Persistence Ignorance (POCO) Adapter for Entity Framework V1</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jkowalski/archive/2008/09/09/persistence-ignorance-poco-adapter-for-entity-framework-v1.aspx" /><id>http://blogs.msdn.com/jkowalski/archive/2008/09/09/persistence-ignorance-poco-adapter-for-entity-framework-v1.aspx</id><published>2008-09-09T19:24:42Z</published><updated>2008-09-09T19:24:42Z</updated><content type="html">&lt;p&gt;One of the limitations of Entity Framework V1 released as part of .NET Framework 3.5 SP1 and Visual Studio 2008 SP1 is lack of support for POCO entity objects. POCO stands for Plain Old CLR Object and refers to an object that does not have any persistence concerns and is not aware of persistence framework. Modern development approaches such as DDD (Domain-Driven Design) and TDD (Test-Driven Development) prefer clear separation of concerns which implies persistence ignorance.&lt;/p&gt; &lt;p&gt;In order to be consumable by EF, entity classes have to:&lt;/p&gt; &lt;ul&gt; &lt;li&gt; &lt;div&gt;Derive from EntityObject class or implement at least one mandatory IPOCO interface: IEntityWithChangeTracker. If the entity participates in relationships it also has to implement IEntityWithRelationships interface. Implementing those interfaces is not hard, but causes entity objects to have a dependency on EF assembly, which is sometimes not desirable&lt;/div&gt; &lt;li&gt; &lt;div&gt;Provide assembly, class and property-level attributes to define mapping from CLR space to model space (we call those O-C mapping attributes)&lt;/div&gt; &lt;li&gt; &lt;div&gt;Use Entity-Framework-provided relationship classes: EntityReference&amp;lt;T&amp;gt;, EntityCollection&amp;lt;T&amp;gt; and RelationshipManager instead of CLR collections (List&amp;lt;T&amp;gt;, ICollection&amp;lt;T&amp;gt;)&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Clearly those requirements make EF’s entity objects persistence-aware.&lt;/p&gt; &lt;p&gt;It is possible to write (generate) an adapter layer that will translate between POCO objects and Entity Framework-aware objects and provide services on top of POCO objects, such as:&lt;/p&gt; &lt;ul&gt; &lt;li&gt; &lt;div&gt;Change tracking (snapshot-based and proxy-based when possible)&lt;/div&gt; &lt;li&gt; &lt;div&gt;Transparent lazy loading&lt;/div&gt; &lt;li&gt; &lt;div&gt;Immutable Value Objects&lt;/div&gt; &lt;li&gt; &lt;div&gt;Queries (LINQ and Entity SQL)&lt;/div&gt; &lt;li&gt; &lt;div&gt;Shadow state (maintaining certain persistence-related fields outside of entity class)&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;We have recently published a sample called &lt;a href="http://code.msdn.microsoft.com/EFPocoAdapter"&gt;EFPocoAdapter&lt;/a&gt; that includes code generator and a supporting library that implements POCO object tracking on top of Entity Framework V1. This serves two purposes:&lt;/p&gt; &lt;ul&gt; &lt;li&gt; &lt;div&gt;To demonstrate that it is possible to track POCO objects using the current version of EF&lt;/div&gt; &lt;li&gt; &lt;div&gt;To gather feedback on POCO-specific features (such as transparent lazy loading, immutable objects, change detection, etc) that customers would like to see implemented natively in future versions of Entity Framework.&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;The source code is released under Microsoft Public License on Code Gallery. There is no formal support for this sample, but we are interested in improving and evolving it based on user’s feedback. For legal reasons we cannot accept source code contributions, but you are more than welcome to share feature ideas and POCO usage scenarios with us.&lt;/p&gt; &lt;h4&gt;Adapter Design&lt;/h4&gt; &lt;p&gt;The main idea used when implementing EFPocoAdapter was the use of adapter objects. Adapters are classes that are EF-friendly (in terms of O/C mapping, relationship manager and so on), but internally manage and materialize POCO objects. Materialization is done transparently by delegating property setters and association change notifications to the POCO object. This way, whenever Entity Framework materializes (hydrates) an adapter object, a corresponding POCO object is also created. Note that property setters not only delegate values to POCO objects, but they also store a copy for themselves – this helps later in the change detection process. &lt;/p&gt; &lt;p&gt;Let’s take a look at a simple adapter class on top of a Region POCO that has 2 properties: RegionID and RegionDescription. It has [EdmEntityType] attribute and [EdmScalarProperty] attributes on every property. Every property setter delegates property write to corresponding property on _pocoEntity object along with firing events necessary for change tracking. A copy of object state is stored in _RegionID and _RegionDescription properties.&lt;/p&gt;&lt;pre class="csharpcode"&gt;[EdmEntityType(NamespaceName=&lt;span class="str"&gt;"NorthwindEFModel"&lt;/span&gt;, Name=&lt;span class="str"&gt;"Region"&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; RegionAdapter : PocoAdapterBase&amp;lt;NorthwindEF.Region&amp;gt;, IPocoAdapter&amp;lt;NorthwindEF.Region&amp;gt;
{
    &lt;span class="kwrd"&gt;private&lt;/span&gt; String _RegionDescription;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; RegionAdapter() { }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; RegionAdapter(NorthwindEF.Region pocoObject) : &lt;span class="kwrd"&gt;base&lt;/span&gt;(pocoObject) { }
    &lt;span class="rem"&gt;// some methods removed...&lt;/span&gt;

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DetectChanges()
    {
        &lt;span class="rem"&gt;// change detection – see below&lt;/span&gt;
    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; Int32 _RegionID;
 
    [EdmScalarProperty(EntityKeyProperty=&lt;span class="kwrd"&gt;true&lt;/span&gt;, IsNullable=&lt;span class="kwrd"&gt;false&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; Int32 RegionID
    {
        get
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; _RegionID;
        }
        set
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (_pocoEntity != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
               &lt;span class="rem"&gt;// pass the property value to POCO object&lt;/span&gt;
                PocoEntity.RegionID = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
            ReportPropertyChanging(&lt;span class="str"&gt;"RegionID"&lt;/span&gt;);
            _RegionID = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            ReportPropertyChanged(&lt;span class="str"&gt;"RegionID"&lt;/span&gt;);
        }
    }

    [EdmScalarProperty(EntityKeyProperty=&lt;span class="kwrd"&gt;false&lt;/span&gt;, IsNullable=&lt;span class="kwrd"&gt;false&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; String RegionDescription
    {
        get
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; _RegionDescription;
        }
        set
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (_pocoEntity != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                PocoEntity.RegionDescription = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }

            ReportPropertyChanging(&lt;span class="str"&gt;"RegionDescription"&lt;/span&gt;);
            _RegionDescription = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            ReportPropertyChanged(&lt;span class="str"&gt;"RegionDescription"&lt;/span&gt;);
        }
    }
}
&lt;/pre&gt;
&lt;p&gt;Change detection is a step that occurs just before changes are saved to the database. Adapter objects compare their stored values and relationship information against information in POCO objects (that users may have changed). If the values differ, adapter sets its own property to the value from POCO object which essentially triggers EF change tracker and ensures that SaveChanges() will persist the object correctly. Change detection looks similar to (in reality more corner cases are covered):&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DetectChanges()
{
  &lt;span class="rem"&gt;// change detection - simplified for explanation purposes&lt;/span&gt;
  &lt;span class="kwrd"&gt;base&lt;/span&gt;.DetectChanges();
  &lt;span class="kwrd"&gt;if&lt;/span&gt; (PocoEntity.RegionID != _RegionID)
    &lt;span class="kwrd"&gt;this&lt;/span&gt;.RegionID = PocoEntity.RegionID;
  &lt;span class="kwrd"&gt;if&lt;/span&gt; (PocoEntity.RegionDescription != _RegionDescription)
    &lt;span class="kwrd"&gt;this&lt;/span&gt;.RegionDescription = PocoEntity.RegionDescription;
}&lt;/pre&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; mso-no-proof: yes"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;DetectChanges() method seems heavy and it really is – it has to store and compare all property values of all objects. Fortunately we can optimize the cost of change detection by introducing Proxies. Proxies are objects that implement POCO interface (by deriving from a POCO class), but they have a hidden dependency on an adapter object. They override all property getters and setters that can be overridden and provide just-in-time change tracking. See the following example of a proxy for Territory class that has a single virtual property called TerritoryDescription:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; TerritoryProxy : NorthwindEF.Territories.Territory
{
    NorthwindEF.Territories.PocoAdapters.TerritoryAdapter _adapter;

    &lt;span class="kwrd"&gt;object&lt;/span&gt; IEntityProxy.Adapter
    {
        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; _adapter; }
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; TerritoryProxy(TerritoryAdapter adapter) { _adapter = adapter; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; String TerritoryDescription
    {
        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;._adapter.TerritoryDescription; }
        set
        {
           &lt;span class="rem"&gt;// pass the value to the POCO property&lt;/span&gt;
            &lt;span class="kwrd"&gt;base&lt;/span&gt;.TerritoryDescription = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;._adapter.Context != &lt;span class="kwrd"&gt;null&lt;/span&gt; 
               &amp;amp;&amp;amp; &lt;span class="kwrd"&gt;value&lt;/span&gt; != &lt;span class="kwrd"&gt;this&lt;/span&gt;._adapter.TerritoryDescription)
            {
               &lt;span class="rem"&gt;// raise change detection event&lt;/span&gt;
              _adapter.Context.RaiseChangeDetected(&lt;span class="kwrd"&gt;this&lt;/span&gt;, 
                     &lt;span class="str"&gt;"TerritoryDescription"&lt;/span&gt;,
                     &lt;span class="kwrd"&gt;this&lt;/span&gt;._adapter.TerritoryDescription, &lt;span class="kwrd"&gt;value&lt;/span&gt;);
            }
           &lt;span class="rem"&gt;// pass the value to the Adapter which triggers change tracker&lt;/span&gt;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;._adapter.TerritoryDescription = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
        }
    }
}&lt;/pre&gt;
&lt;p&gt;Adapters are not meant to be seen in any scenarios and users should not be aware of their existence. To do this, we need to expose a programmable layer that hides adapters completely. We need to be able to specify LINQ to Entities queries in terms of POCO objects (similar to ObjectQuery&amp;lt;T&amp;gt;) and we want inserts/attaches/deletes to work too. We are introducing a new object called EntitySet&amp;lt;T&amp;gt;, that combines function of ObjectQuery&amp;lt;T&amp;gt; and object-management methods (AddToX(), AttachTo(), DeleteObject()). We are also generating a replacement for ObjectContext, which makes the end-to-end programming experience with POCOs more natural. See the "Working with POCO classes” section below for more usage information.&lt;/p&gt;
&lt;h4&gt;Components&lt;/h4&gt;
&lt;p&gt;The sample includes two main components:&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpFirst" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l3 level1 lfo2"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;EFPocoAdapter - library which you reference in your applications&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpLast" style="margin: 0in 0in 10pt 0.5in; text-indent: -0.25in; mso-list: l3 level1 lfo2"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;EFPocoClassGen - code generator which generates the adapter layer&lt;/p&gt;
&lt;p&gt;To use the sample you will need five additional pieces of the puzzle:&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpFirst" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l3 level1 lfo2"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;POCO classes (you typically write them by hand, the sample includes NorthwindEF project)&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l3 level1 lfo2"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;POCO container – root object used for querying POCO (equivalent of ObjectContext for persistence-aware objects). &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l3 level1 lfo2"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;POCO adapter – generated&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l3 level1 lfo2"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Entity Data Model (CSDL,SSDL &amp;amp; MSL files)&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpLast" style="margin: 0in 0in 10pt 0.5in; text-indent: -0.25in; mso-list: l3 level1 lfo2"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Connection string (in your App.config or in code)&lt;/p&gt;
&lt;p&gt;In a typical case you will generate POCO classes or write them by hand, but EFPocoClassGen has a mode to generate them from an existing model. &lt;/p&gt;
&lt;p&gt;POCO container can be written by hand or generated from a CSDL file. &lt;/p&gt;
&lt;p&gt;POCO Adapter for your model is generated at compile time or at runtime. In the former case, you will be able to debug the adapter code as the source code will be stored on your hard drive. In the latter case, your application will include just classes written by hand and no artificial artifacts.&lt;/p&gt;
&lt;h2 style="margin: 10pt 0in 0pt"&gt;Compile-Time Adapter Generation&lt;/h2&gt;
&lt;p&gt;EFPocoClassGen has three modes and can generate:&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpFirst" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l3 level1 lfo2"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;POCO Adapter (default)&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l3 level1 lfo2"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;POCO container&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpLast" style="margin: 0in 0in 10pt 0.5in; text-indent: -0.25in; mso-list: l3 level1 lfo2"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;POCO classes&lt;/p&gt;
&lt;p&gt;Assuming you want to generate a POCO adapter for classes that are stored in NorthwindEF.dll and your model is in NorthwindEFModel.csdl, you should run the following command:&lt;/p&gt;&lt;pre class="csharpcode"&gt;EFPocoClassGen.exe /incsdl:NorthwindEFModel.csdl /outputfile:PocoAdapter.cs 
                   /&lt;span class="kwrd"&gt;ref&lt;/span&gt;:NorthwindEF.dll /map:NorthwindEFModel=NorthwindEF&lt;/pre&gt;
&lt;p&gt;This will generate PocoAdapter.cs file based on NorthwindEFModel.csdl (specified in /incsdl option). By specifying /ref argument, you allow class generator to scan the assembly and generate certain optimizations such as proxy-based change tracking for virtual properties. This is optional but if you don’t provide the assembly references you will have to put optimization hints in the CSDL file manually. /map allows you to use a different namespace in CSDL than in your classes. Code generator has some more options; to see them all, run it without any parameters.&lt;/p&gt;
&lt;p&gt;It is usually best to automate code generation for a project by putting the appropriate commands in Pre-Build Step of VS project or in BeforeCompile target in MSBuild script. The generator will not regenerate the output file if the input hasn’t changed, so you will not get unnecessary recompiles because of that.&lt;/p&gt;
&lt;h2 style="margin: 10pt 0in 0pt"&gt;POCO Container&lt;/h2&gt;
&lt;p&gt;The POCO Container is a simple class that derives from EFPocoContext. It has a bunch of properties representing top-level entity sets. All methods that developers interact with are defined in the base class or in entity set methods.&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; NorthwindEntities : EFPocoContext&amp;lt;NorthwindEF.PocoAdapters.NorthwindEntitiesAdapter&amp;gt;
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; NorthwindEntities()
     : &lt;span class="kwrd"&gt;base&lt;/span&gt;(&lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindEntitiesAdapter()) { }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; NorthwindEntities(&lt;span class="kwrd"&gt;string&lt;/span&gt; connectionString)
     : &lt;span class="kwrd"&gt;base&lt;/span&gt;(&lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindEntitiesAdapter(connectionString)) { }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; NorthwindEntities(EntityConnection connection)
     : &lt;span class="kwrd"&gt;base&lt;/span&gt;(&lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindEntitiesAdapter(connection)) { }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; IEntitySet&amp;lt;NorthwindEF.Employee&amp;gt; Employees
    {
        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; GetEntitySet&amp;lt;NorthwindEF.Employee&amp;gt;(&lt;span class="str"&gt;"Employees"&lt;/span&gt;); }
    }
 
    &lt;span class="kwrd"&gt;public&lt;/span&gt; IEntitySet&amp;lt;NorthwindEF.Order&amp;gt; Orders
    {
        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; GetEntitySet&amp;lt;NorthwindEF.Order&amp;gt;(&lt;span class="str"&gt;"Orders"&lt;/span&gt;); }
    }
 
    &lt;span class="rem"&gt;// additional entity sets removed for brevity&lt;/span&gt;
}&lt;/pre&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal; mso-layout-grid-align: none"&gt;To generate POCO container, run the same command as above with /mode:PocoContainer – just be sure to specify a different output file: &lt;/p&gt;&lt;pre class="csharpcode"&gt;EFPocoClassGen.exe /mode:PocoContainer /incsdl: NorthwindEFModel.csdl /outputfile:NorthwindEntities.cs &lt;br&gt;                   /ref:NorthwindEF.dll /map:NorthwindEFModel=NorthwindEF &lt;/pre&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal; mso-layout-grid-align: none"&gt;If you prefer, you can also write the class by hand – the class needs to have as many entity set properties as you require (not all EntitySets from CSDL have to exposed) and has to have one or more of the constructors as seen above.&lt;/p&gt;
&lt;h4&gt;Setting Up the Solution&lt;/h4&gt;
&lt;p&gt;The recommended way of setting up your solution when using compile-time code generation is:&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpFirst" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l0 level1 lfo3"&gt;&lt;span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: ignore"&gt;1.&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Put all POCO classes in a separate assembly, say NorthwindEF.dll. The assembly doesn’t need to have any references (other than mscorlib.dll and maybe System.Core.dll)&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l0 level1 lfo3"&gt;&lt;span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: ignore"&gt;2.&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Create a separate library project for your adapter, name it for example NorthwindEF.PocoAdapter.dll Add references to System.Data.Entity.dll, EFPocoAdapter.dll and NorthwindEF.dll&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l0 level1 lfo3"&gt;&lt;span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: ignore"&gt;3.&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Set up pre-build scripts that will generate PocoAdapter.cs and NorthwindEntities.cs. Build the project once and add generated files to the project (you don’t have to add them to source control as they will be regenerated at build time)&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpLast" style="margin: 0in 0in 10pt 0.5in; text-indent: -0.25in; mso-list: l0 level1 lfo3"&gt;&lt;span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: ignore"&gt;4.&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;In your code that uses the POCO adapter, add references to: EFPocoAdapter.dll, NorthwindEF.dll, NorthwindEF.PocoAdapter.dll and System.Data.Entity.dll&lt;/p&gt;
&lt;p&gt;POCO Adapter can be also generated at runtime using EFPocoAdapterGenerator class:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;// set up generator&lt;/span&gt;
var generator = &lt;span class="kwrd"&gt;new&lt;/span&gt; EFPocoAdapterGenerator&amp;lt;MyHandWrittenNorthwindEntities&amp;gt;();
generator.EntityConnectionString = &lt;span class="str"&gt;"name=NorthwindEntities"&lt;/span&gt;;
generator.EdmToClrNamespaceMapping[&lt;span class="str"&gt;"NorthwindEFModel"&lt;/span&gt;] = &lt;span class="str"&gt;"NorthwindEF"&lt;/span&gt;;
generator.GenerateProxies = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
generator.ObjectAssemblies.Add(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Customer).Assembly);
generator.ObjectAssemblies.Add(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Territory).Assembly);

&lt;span class="rem"&gt;// generate adapter and create context factory&lt;/span&gt;
var factory = generator.CreateContextFactory();

&lt;span class="rem"&gt;// use generated context&lt;/span&gt;
&lt;span class="kwrd"&gt;using&lt;/span&gt; (var context = factory.CreateContext())
{
    Assert.IsInstanceOfType(context, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyHandWrittenNorthwindEntities));
    var cust = context.Customers.First(c =&amp;gt; c.CustomerID == &lt;span class="str"&gt;"ALFKI"&lt;/span&gt;);
}
&lt;/pre&gt;
&lt;p&gt;See EFPocoAdapterGeneratorTests class for a full working example.&lt;/p&gt;
&lt;h4&gt;Working with POCO classes&lt;/h4&gt;
&lt;p&gt;Usage patterns of the generated POCO adapter layer are very similar to regular EF, but because objects are now persistence-ignorant, some APIs have been changed. This section describes important differences:&lt;/p&gt;
&lt;h3 style="margin: 10pt 0in 0pt"&gt;Managing POCO Container&lt;/h3&gt;
&lt;p&gt;POCO Container should be managed in the same way as a regular ObjectContext. Same rules and recommendations apply. It is usually best to have short-living contexts and ensure proper disposal of all resources, preferably with the use of the using statement:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; (NorthwindEntities context = &lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindEntities())
{
    &lt;span class="rem"&gt;// use context&lt;/span&gt;
}&lt;/pre&gt;
&lt;h3 style="margin: 10pt 0in 0pt"&gt;Queries&lt;/h3&gt;
&lt;p&gt;EFPocoContext exposes CreateQuery&amp;lt;T&amp;gt; which internally wraps ObjectQuery&amp;lt;T&amp;gt;. POCO context also exposes entity sets that can be used to query objects using LINQ to Entities, ESQL builder methods and Entity SQL. Of course, you can still use EntityClient and EntityCommand to do queries in the value layer.&lt;/p&gt;
&lt;p&gt;In short: queries look exactly the same as in EF, just entity types and query object types are different.&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; (NorthwindEntities context = &lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindEntities())
{
    Customer k = (from c &lt;span class="kwrd"&gt;in&lt;/span&gt; context.Customers 
                  &lt;span class="kwrd"&gt;where&lt;/span&gt; c.CustomerID == &lt;span class="str"&gt;"ALFKI"&lt;/span&gt;
                  select c).First();
    Console.WriteLine(k.Address.City);
}&lt;/pre&gt;
&lt;p&gt;See QueryTests.cs and BuilderMethodsTests.cs for more examples of usage. &lt;/p&gt;
&lt;h3 style="margin: 10pt 0in 0pt"&gt;Inserting, Removing and Attaching Objects&lt;/h3&gt;
&lt;p&gt;POCO context code exposes IEntitySet&amp;lt;T&amp;gt; properties that can be used to query (because they derive from IQueryable&amp;lt;T&amp;gt;) but also insert, remove and attach objects to the context. This is a change from EF where you used to use AddObject(), AttachTo() and DeleteObject() on ObjectContext class. The idea of exposing EntitySet&amp;lt;T&amp;gt; object to aggregate all operations to entity sets was originally introduced in the &lt;a href="http://code.msdn.microsoft.com/EFExtensions"&gt;EFExtensions&lt;/a&gt; project:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; (NorthwindEntities context = &lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindEntities(conn))
{
  &lt;span class="rem"&gt;// add new object&lt;/span&gt;
  context.Customers.InsertOnSaveChanges(&lt;span class="kwrd"&gt;new&lt;/span&gt; Customer { 
      CustomerID = &lt;span class="str"&gt;"YYYY"&lt;/span&gt;, 
      CompanyName = &lt;span class="str"&gt;"Una Firma"&lt;/span&gt; 
  });

  &lt;span class="rem"&gt;// attach existing object for tracking&lt;/span&gt;
  var product = &lt;span class="kwrd"&gt;new&lt;/span&gt; Product(&lt;span class="kwrd"&gt;new&lt;/span&gt; Supplier()) { ProductID = 1 };
  context.Products.Attach(product);

  &lt;span class="rem"&gt;// locate and delete object&lt;/span&gt;
  var cust = context.Customers.First(c =&amp;gt; c.CustomerID == &lt;span class="str"&gt;"XXXX"&lt;/span&gt;);
  context.Customers.DeleteOnSaveChanges(cust);

  &lt;span class="rem"&gt;// persist changes&lt;/span&gt;
  context.SaveChanges();
}&lt;/pre&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal; mso-layout-grid-align: none"&gt;See EntitySetTests.cs and CRUDTests.cs for more examples.&lt;/p&gt;
&lt;h3 style="margin: 10pt 0in 0pt"&gt;Transparent Lazy Loading&lt;/h3&gt;
&lt;p&gt;Lazy loading happens automatically when you reference a virtual property on an entity object that was retrieved from a query. Because the property is marked as virtual, EFPocoClassGen generates a derived class called a proxy, which overrides the property and provides lazy-loading behavior on it.&lt;/p&gt;
&lt;p&gt;Similar thing happens for collections – they get loaded on first access, but in this case the collection accessor doesn’t have to be declared virtual but its type must be an interface (ICollection&amp;lt;T&amp;gt;, IList&amp;lt;T&amp;gt;) instead of a concrete class (such as List&amp;lt;T&amp;gt;). In this case POCO adapter initializes the collection with a tracked collection that provides transparent lazy loading on enumeration and other types of access.&lt;/p&gt;
&lt;p&gt;You can disable this lazy loading behavior at runtime, by setting EFPocoContext.EnableLazyLoading property to false or at compile time, by passing /enableLazyLoading:false to EFPocoClassGen. Note that if compile your adapter classes without lazy loading support, you won’t be able to enable lazy loading at runtime.&lt;/p&gt;
&lt;p&gt;If the lazy loading has been disabled, you can still load a reference or collection you want to navigate to by using new methods on EFPocoContext:&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpFirst" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l2 level1 lfo4"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;IsPropertyLoaded(o,p) – determines whether object or collection represented by property p on object o has been loaded. Property can be specified as a string or as a strongly typed lambda.&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpLast" style="margin: 0in 0in 10pt 0.5in; text-indent: -0.25in; mso-list: l2 level1 lfo4"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;LoadProperty(o,p) – loads the related end of the navigation property p on object o. Property can be specified as a string or as a strongly typed lambda.&lt;/p&gt;
&lt;p&gt;See LazyLoadingTests.cs for example usage.&lt;/p&gt;
&lt;h3 style="margin: 10pt 0in 0pt"&gt;Object-to-Conceptual Mapping&lt;/h3&gt;
&lt;p&gt;You can specify the namespace mapping (from conceptual space to CLR space) when generating POCO adapter using /map parameter to EFPocoClassGen. If you need to fine-tune this (for example to materialize a class from another assembly or namespace), you can attach an attribute called ClrType to &amp;lt;EntityType&amp;gt; or &amp;lt;ComplexType&amp;gt; in your CSDL schema.&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;EntityType&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="CurrentEmployee"&lt;/span&gt; &lt;span class="attr"&gt;BaseType&lt;/span&gt; &lt;span class="kwrd"&gt;="NorthwindEFModel.Employee"&lt;/span&gt; &lt;br&gt;            &lt;span class="attr"&gt;objectmapping:ClrType&lt;/span&gt;&lt;span class="kwrd"&gt;="Some.Clr.Namespace.CurrentEmployee"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal; mso-layout-grid-align: none"&gt;The sample comes with NorthwindEF schema split into two assemblies: NorthwindEF and NorthwindEF.Territories.dll and classes live in three namespaces to demonstrate this concept. See NorthwindEFModel.csdl for details.&lt;/p&gt;
&lt;h3 style="margin: 10pt 0in 0pt"&gt;Read-Only Value Objects&lt;/h3&gt;
&lt;p&gt;You can map your entities to classes that are read-only and all they do is a public constructor that initializes all properties. You can also have some properties read-only and others settable. All you have to do to get this to work is to use a constructor parameter naming convention. If the property is read-only, the adapter will pass its initial value as the corresponding constructor argument:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;struct&lt;/span&gt; CommonAddress
{
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; _address;
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; _city;
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; _region;
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; _postalCode;
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; _country;

    &lt;span class="kwrd"&gt;public&lt;/span&gt; CommonAddress(&lt;span class="kwrd"&gt;string&lt;/span&gt; address, &lt;span class="kwrd"&gt;string&lt;/span&gt; city, &lt;span class="kwrd"&gt;string&lt;/span&gt; region, 
                         &lt;span class="kwrd"&gt;string&lt;/span&gt; postalCode, &lt;span class="kwrd"&gt;string&lt;/span&gt; country)
    {
        _address = address;
        _city = city;
        _region = region;
        _postalCode = postalCode;
        _country = country;
    }
 
    &lt;span class="kwrd"&gt;public&lt;/span&gt; String Address
    {
        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; _address; }
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; String City
    {
        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; _city; }
    }
 
    &lt;span class="kwrd"&gt;public&lt;/span&gt; String Region
    {
        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; _region; }
    }
 
    &lt;span class="kwrd"&gt;public&lt;/span&gt; String PostalCode
    {
        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; _postalCode; }
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; String Country
    {
        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; _country; }
    }
}

&lt;/pre&gt;
&lt;p&gt;See CommonAddress.cs, Product.cs and Category.cs for more examples of usage.&lt;/p&gt;
&lt;h3 style="margin: 10pt 0in 0pt"&gt;Change Tracking&lt;/h3&gt;
&lt;p&gt;Change tracking for scalar properties and complex types is implemented in one of two modes: snapshot-based or proxy-based. Snapshot-based change tracking means that when EF materializes an object, the adapter stores a copy of its field values for further comparison. This way it knows which fields have changes and can notify object state manager accordingly.&lt;/p&gt;
&lt;p&gt;Proxy-based change tracking is used when you declare your POCO object property to be virtual. EFPocoClassGen generates a proxy class that overrides all virtual properties in your POCO classes and injects notifications that update object state manager just-in-time.&lt;/p&gt;
&lt;p&gt;Change tracking for collections can also use snapshots or proxies – in the first case EntityCollection&amp;lt;T&amp;gt; managed by ObjectStateManager is used as original values, if proxies are used (only possible when collection formal type is ICollection&amp;lt;T&amp;gt; or IList&amp;lt;T&amp;gt;) the Object State Manager gets updated just-in-time.&lt;/p&gt;
&lt;p&gt;Change detection happens just before changes are saved to the database. You can force it by calling DetectChanges() on ObjectStateManager. Forcing change detection can be useful to do relationship fixup before changes are saved. It also raises change tracking events.&lt;/p&gt;
&lt;p&gt;There are 2 change tracking events on EFPocoContext:&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpFirst" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l2 level1 lfo4"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;ChangeDetected that gets raised whenever a change is detected on a scalar, complex type property or a relationship where related end is of single cardinality&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpLast" style="margin: 0in 0in 10pt 0.5in; text-indent: -0.25in; mso-list: l2 level1 lfo4"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;CollectionChangeDetected that gets raised whenever a change in collection contents is detected&lt;/p&gt;
&lt;p&gt;You can hook up those events for debugging purposes, but there may be other possible uses, such as auditing or tracing.&lt;/p&gt;
&lt;h3 style="margin: 10pt 0in 0pt"&gt;Compiled Queries&lt;/h3&gt;
&lt;p&gt;Compiled queries work in the same way as in EF, except that you use EFPocoCompiledQuery.Compile() instead of CompiledQuery.Compile()&lt;/p&gt;&lt;pre class="csharpcode"&gt;var getCustomerByID = EFPocoCompiledQuery.Compile(
   (NorthwindEntities context, &lt;span class="kwrd"&gt;string&lt;/span&gt; customerID) =&amp;gt;
       context.Customers.Where(c =&amp;gt; c.CustomerID == customerID).First());

&lt;span class="kwrd"&gt;using&lt;/span&gt; (NorthwindEntities context = &lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindEntities())
{
    var alfki = getCustomerByID(context, &lt;span class="str"&gt;"ALFKI"&lt;/span&gt;);
}&lt;/pre&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal; mso-layout-grid-align: none"&gt;See CompiledQueryTests.cs for more information.&lt;/p&gt;
&lt;h3 style="margin: 10pt 0in 0pt"&gt;Working With Proxies&lt;/h3&gt;
&lt;p&gt;Proxies are injected automatically when EFPocoAdapter materializes new POCO objects. This applies to all objects being results of queries and does NOT apply to objects passed by users.&lt;/p&gt;
&lt;p&gt;Users can force a proxy to be created by calling EFPocoContext.CreateObject&amp;lt;T&amp;gt; instead of new T().&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; (NorthwindEntities context = &lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindEntities())
{
    var cust = context.CreateObject&amp;lt;Customer&amp;gt;();
    Assert.IsTrue(context.IsProxy(cust));
}&lt;/pre&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal; mso-layout-grid-align: none"&gt;Users can also enable and disable proxy use (which effectively disables transparend lazy loading) by setting EFPocoContext.EnableChangeTrackingUsingProxies property to false. Note that this applies to newly materialized objects, not to objects that have already been created and managed by the context. You can convert your existing POCO objects to Proxies with and back with ConvertPocoToProxies() and ConvertProxiesToPoco() methods accordingly.&lt;/p&gt;
&lt;h3 style="margin: 10pt 0in 0pt"&gt;Shadow State&lt;/h3&gt;
&lt;p&gt;Sometimes we want to hide certain properties from POCO objects and let the framework managed them. For example, we typically don’t need to see GUIDs, timestamp or version values used for optimistic concurrency checks as long as the framework can manage them automatically. The state for those properties can still be maintained by the adapter, but the property doesn’t have to be present on the POCO object.&lt;/p&gt;
&lt;p&gt;In the similar manner we may want to hide primary keys if they don’t have business value, provided that there you have defined your column as IDENTITY. &lt;/p&gt;
&lt;p&gt;For example, the following POCO class:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Territory
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; TerritoryDescription { get; set; }
}&lt;/pre&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Is declared in CSDL as:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;EntityType&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Territory"&lt;/span&gt; &lt;span class="attr"&gt;objectmapping:ClrType&lt;/span&gt;&lt;span class="kwrd"&gt;="NorthwindEF.Territories.Territory"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Key&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;PropertyRef&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="TerritoryID"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Key&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="TerritoryID"&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="Int32"&lt;/span&gt; &lt;span class="attr"&gt;Nullable&lt;/span&gt;&lt;span class="kwrd"&gt;="false"&lt;/span&gt;
            &lt;span class="attr"&gt;objectmapping:ChangeTracking&lt;/span&gt;&lt;span class="kwrd"&gt;="Hidden"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="TerritoryDescription"&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="String"&lt;/span&gt; &lt;span class="attr"&gt;Nullable&lt;/span&gt;&lt;span class="kwrd"&gt;="false"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;EntityType&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Note the use of &lt;span style="font-size: 10pt; color: red; line-height: 115%; font-family: 'Courier New'; mso-no-proof: yes"&gt;objectmapping:ChangeTracking&lt;/span&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%; font-family: 'Courier New'; mso-no-proof: yes"&gt;=&lt;/span&gt;&lt;span style="font-size: 10pt; line-height: 115%; font-family: 'Courier New'; mso-no-proof: yes"&gt;"&lt;span style="color: blue"&gt;Hidden&lt;/span&gt;"&lt;/span&gt; to notify the code generator that the property is not present on the POCO class. This is optional if you use /ref: as in this case the code generator can detect that the property is missing and automatically assume “shadow” property.&lt;/p&gt;
&lt;h3 style="margin: 10pt 0in 0pt"&gt;Other Properties of EFPocoContext &lt;/h3&gt;
&lt;p&gt;EFPocoContext exposes several helper properties, similar to ObjectContext:&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpFirst" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l2 level1 lfo4"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;MetadataWorkspace – gives you access to metadata workspace for the model&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l2 level1 lfo4"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;QueryProvider – exposes IQueryProvider used to translate LINQ queries to the form that Linq To Entities understands&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpLast" style="margin: 0in 0in 10pt 0.5in; text-indent: -0.25in; mso-list: l2 level1 lfo4"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Connection – gives you access to underlying EntityConnection&lt;/p&gt;
&lt;h2 style="margin: 10pt 0in 0pt"&gt;Limitations&lt;/h2&gt;
&lt;p&gt;The first version of the sample has certain limitations. Not all APIs of EF are wrapped and exposed in a POCO-friendly manner. You can still access the following APIs through adapter objects:&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpFirst" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l2 level1 lfo4"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;ObjectStateManager/ObjectStateEntry&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l2 level1 lfo4"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Query modes other than AppendOnly&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpLast" style="margin: 0in 0in 10pt 0.5in; text-indent: -0.25in; mso-list: l2 level1 lfo4"&gt;&lt;span style="font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;·&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;ObjectResult and other databinding-specific classes&lt;/p&gt;
&lt;p&gt;It should be relatively straightforward to add the wrappers as needed using techniques described in the article.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8936938" width="1" height="1"&gt;</content><author><name>jkowalski</name><uri>http://blogs.msdn.com/members/jkowalski.aspx</uri></author><category term="Entity Framework" scheme="http://blogs.msdn.com/jkowalski/archive/tags/Entity+Framework/default.aspx" /><category term="EFPocoAdapter" scheme="http://blogs.msdn.com/jkowalski/archive/tags/EFPocoAdapter/default.aspx" /></entry><entry><title>Transparent Caching Support for Entity Framework one-pager</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jkowalski/archive/2008/07/10/caching-one-pager.aspx" /><id>http://blogs.msdn.com/jkowalski/archive/2008/07/10/caching-one-pager.aspx</id><published>2008-07-10T22:02:00Z</published><updated>2008-07-10T22:02:00Z</updated><content type="html">&lt;P&gt;We've just posted a one-pager on transparent caching support in Entity Framework on our &lt;A class="" href="http://blogs.msdn.com/efdesign/" mce_href="http://blogs.msdn.com/efdesign/"&gt;EFDesign blog&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/efdesign/archive/2008/07/09/transparent-caching-support-in-the-entity-framework.aspx"&gt;http://blogs.msdn.com/efdesign/archive/2008/07/09/transparent-caching-support-in-the-entity-framework.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;We want to make sure that you will be able to interface EF caching with various caching solutions, so we would be very grateful for comments on proposed ICache interface.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8718220" width="1" height="1"&gt;</content><author><name>jkowalski</name><uri>http://blogs.msdn.com/members/jkowalski.aspx</uri></author><category term="EFLazyLoading" scheme="http://blogs.msdn.com/jkowalski/archive/tags/EFLazyLoading/default.aspx" /><category term="Caching" scheme="http://blogs.msdn.com/jkowalski/archive/tags/Caching/default.aspx" /></entry><entry><title>Software Development Meme</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jkowalski/archive/2008/07/07/software-development-meme.aspx" /><id>http://blogs.msdn.com/jkowalski/archive/2008/07/07/software-development-meme.aspx</id><published>2008-07-07T21:29:22Z</published><updated>2008-07-07T21:29:22Z</updated><content type="html">&lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;I was recently &lt;a href="http://blogs.msdn.com/dsimmons/archive/2008/07/07/software-development-meme.aspx" target="_blank"&gt;tagged by Danny&lt;/a&gt; to answer questions about my programming experience as part of a &lt;a href="http://oakleafblog.blogspot.com/2008/07/software-development-meme.html" target="_blank"&gt;longer&lt;/a&gt; &lt;a href="http://blogs.devsource.com/devlife/content/random/software_development_meme_1.html" target="_blank"&gt;chain letter&lt;/a&gt;, so here they are:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;strong&gt;How old were you when you first started programming &lt;/strong&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;I was 8 (some 0x17 years ago) when I got my first computer: &lt;a href="http://en.wikipedia.org/wiki/Timex_Computer_2048"&gt;Timex 2048&lt;/a&gt; which was &lt;a href="http://en.wikipedia.org/wiki/ZX_Spectrum"&gt;ZX Spectrum&lt;/a&gt; clone sold in Poland. Originally I was planning to use it for gaming. Unfortunately my computer didn&amp;#8217;t come with an essential component (a tape recorder &lt;span style="font-family: wingdings; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin; mso-char-type: symbol; mso-symbol-font-family: wingdings"&gt;&lt;span style="mso-char-type: symbol; mso-symbol-font-family: wingdings"&gt;J&lt;/span&gt;&lt;/span&gt;), so I really had no choice but to learn programming.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;span style="mso-ascii-font-family: calibri; mso-hansi-font-family: calibri; mso-bidi-font-family: arial"&gt;&lt;strong&gt;How did you get started in programming? &lt;/strong&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;Fortunately Timex had a built-in BASIC language interpreter and it came with a nice language manual. I started exploring that and found that I could do cool things with programs. First things I tried were graphics-related and used PLOT/DRAW combo extensively to produce some nice geometric patterns.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;Later I realized that there was another language that my computer understood which was much faster: Z80 assembly language (the computer manual even included an introduction to Z80 assembly &lt;span style="mso-spacerun: yes"&gt;&amp;#160;&lt;/span&gt;- compare it with today&amp;#8217;s manuals!) so I learned about it (with the help of GENS assembler and MONS debugger and &amp;#8220;The Complete Spectrum ROM Disassembly&amp;#8221; book) and quickly fell in love with it.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt 0.5in"&gt;Side-note: because programs for ZX Spectrum were mostly distributed on audio tapes (with a buzzing sound on it kind of similar to a modem negotiating connection), some people in Poland came up with a super clever idea of distributing programs during radio shows in the middle of the night. The show was called &amp;#8220;RadioKomputer&amp;#8221; and that&amp;#8217;s how I got some educational programs.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;span style="mso-ascii-font-family: calibri; mso-hansi-font-family: calibri; mso-bidi-font-family: arial"&gt;&lt;strong&gt;What was your first language? &lt;/strong&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;My first languages were Sinclair Basic and Z80 assembly, many years later I moved to a PC (386 SX with 2MB of RAM) and then I started playing with Turbo Pascal &amp;amp; Turbo C from Borland. &lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;span style="mso-ascii-font-family: calibri; mso-hansi-font-family: calibri; mso-bidi-font-family: arial"&gt;&lt;strong&gt;What was the first real program you wrote? &lt;/strong&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;I don&amp;#8217;t remember what the &lt;u&gt;first&lt;/u&gt; real program was, there were many of them, most were graphics related. I wrote some flashy graphics demos in assembly language which included some scrolling text, nice graphics, explosions, music (such as &amp;#8220;Axel F&amp;quot; theme or Jean Michel Jarre because it was the only thing that sounded ok on Timex beeper). We demoed those on computer fairs which were organized every week in a nearby high school.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;Later, on PC I wrote my first &lt;a href="http://en.wikipedia.org/wiki/Norton%20Commander"&gt;Norton Commander&lt;/a&gt; clone. Everyone else I knew had also written their own clones, too &amp;#8211; I guess it was kind of a sport in the nineties. I was proud of my Jarek Commander, because it only took &amp;lt;500 bytes of resident memory while original NC consumed some 4 KB (in the world of 640K this was a huge difference).&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;My first big program (sometime around 1994-95) was a graphics program called &amp;#8220;Canaletto&amp;#8221; named after Bernardo Belotto who was a 18th century painter. It was a fully featured graphics package for DOS which included drawing and image processing capabilities (like MS Paint on steroids with some basic image processing effects which you can see in Adobe Photoshop today). I wrote everything from scratch in Turbo C &amp;amp; 8086 assembly, including my own windowing library, printing support, image processing algorithms and even some graphics drivers for non-VESA video cards. We wanted to sell Canaletto to Get Rich Quickly(tm). We prepared the first &amp;#8220;batch&amp;#8221; in my friend&amp;#8217;s kitchen using his color printer and even shrink-wrapped the boxes manually using his gas stove. We sold whopping 3 copies and 33% of buyers have registered their copies by mailing in registration cards.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;span style="mso-ascii-font-family: calibri; mso-hansi-font-family: calibri; mso-bidi-font-family: arial"&gt;&lt;strong&gt;What languages have you used since you started programming? &lt;/strong&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;Sinclair Basic, Z80 assembly, Turbo Pascal, C/C++, 80386 assembly, Java, JavaScript, Perl, Python, C#, Awk, Unix shell scripts, SQL, HTML, XML/XSLT/XPath/XQuery. I have also experimented with countless other languages such as Smalltalk, Boo, functional languages and more. &lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;span style="mso-ascii-font-family: calibri; mso-hansi-font-family: calibri; mso-bidi-font-family: arial"&gt;&lt;strong&gt;What was your first professional programming gig? &lt;/strong&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;My first professional software development project was a PC game called &amp;#8220;&lt;a href="http://www.gamespot.com/pc/strategy/roborumble/index.html"&gt;RoboRumble&lt;/a&gt;&amp;#8221; which was produced in 1998 and released worldwide. It was a real-time strategy in 3D with some &lt;a href="http://www.ag.ru/screenshots/roborumble/37853"&gt;very cool&lt;/a&gt; &lt;a href="http://www.ag.ru/screenshots/roborumble/15228"&gt;accelerated graphics&lt;/a&gt;. I was responsible for gameplay, AI, multiplayer and various putting-it-all-together tasks.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;After that experience I moved on to do some more &amp;#8220;serious&amp;#8221; development. I spent next 7 years building large workflow systems for enterprises. I implemented at least three O/R Mappers along the way. I just didn&amp;#8217;t know that those things were called O/RM back then.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;strong&gt;&lt;span style="mso-ascii-font-family: calibri; mso-hansi-font-family: calibri; mso-bidi-font-family: arial"&gt;If you knew then what you know now, would you have started programming?&lt;/span&gt;&lt;span style="mso-ascii-font-family: calibri; mso-hansi-font-family: calibri; mso-bidi-font-family: arial"&gt;&amp;#160; &lt;/span&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;span style="mso-ascii-font-family: calibri; mso-hansi-font-family: calibri; mso-bidi-font-family: arial"&gt;Absolutely! &lt;/span&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;span style="mso-ascii-font-family: calibri; mso-hansi-font-family: calibri; mso-bidi-font-family: arial"&gt;&lt;strong&gt;If there is one thing you learned along the way that you would tell new developers, what would it be? &lt;/strong&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;It&amp;#8217;s all about requirements. No matter how cool the code is, it is useless if it doesn&amp;#8217;t do what the customer wants. Customers often don&amp;#8217;t know what they want, so it takes a lot of communication skills to &amp;#8220;extract&amp;#8221; that information. Also, be prepared for ever-changing requirements and incorporate them in your development process. &lt;a href="http://en.wikipedia.org/wiki/BDUF"&gt;BDUF&lt;/a&gt; rarely wins against &lt;a href="http://en.wikipedia.org/wiki/Agile_software_development"&gt;agile practices&lt;/a&gt;. Usability is also extremely important; even if the customer does not realize the importance of it, you should do all you possibly can to make common user scenarios very easy to use and other scenarios possible.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;span style="mso-ascii-font-family: calibri; mso-hansi-font-family: calibri; mso-bidi-font-family: arial"&gt;&lt;strong&gt;What's the most fun you've ever had ... programming? &lt;/strong&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;Definitely working on RoboRumble was a lot of fun. In the end-game we spent like 20 hours a day working on finishing the product (we literally left @4 AM just to get back at 8AM) but despite some local frustrations we absolutely loved it.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;span style="mso-ascii-font-family: calibri; mso-hansi-font-family: calibri; mso-bidi-font-family: arial"&gt;&lt;strong&gt;Who&amp;#8217;s next &lt;/strong&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;Because of the exponential nature of this chain letter it is increasingly complex to find more people with blogs, but here are the next nominees:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 10pt"&gt;&lt;a href="http://blogs.msdn.com/esql/"&gt;Zlatko Michailov&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://blogs.msdn.com/sceppa/"&gt;David Sceppa&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://blogs.msdn.com/juyik/"&gt;Ju-Yi Kuo&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/maurycy/" target="_blank"&gt;Maurycy Markowski&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8703424" width="1" height="1"&gt;</content><author><name>jkowalski</name><uri>http://blogs.msdn.com/members/jkowalski.aspx</uri></author><category term="Personal" scheme="http://blogs.msdn.com/jkowalski/archive/tags/Personal/default.aspx" /></entry><entry><title>Sample Entity Framework Provider for Oracle</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jkowalski/archive/2008/06/23/sample-entity-framework-provider-for-oracle.aspx" /><id>http://blogs.msdn.com/jkowalski/archive/2008/06/23/sample-entity-framework-provider-for-oracle.aspx</id><published>2008-06-24T01:54:05Z</published><updated>2008-06-24T01:54:05Z</updated><content type="html">&lt;p&gt;I wanted to let you know that we have just released Sample Entity Framework Provider for Oracle on MSDN Code Gallery.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://code.msdn.com/EFOracleProvider"&gt;http://code.msdn.com/EFOracleProvider&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The provider is implemented using essentially the same technique as &lt;a href="http://code.msdn.microsoft.com/EFSampleProvider" target="_blank"&gt;EFSampleProvider&lt;/a&gt;, but targets System.Data.OracleClient instead of System.Data.SqlClient. The provider is compatible with Visual Studio SP1 Beta and the code is released under Microsoft Public License (Ms-PL).&lt;/p&gt;  &lt;p&gt;There are three notable features of this provider:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Non-default type mappings&lt;/strong&gt;. In EFOracleProviderManifest we are supporting non-default type mappings:       &lt;ul&gt;       &lt;li&gt;EFOracle.number(1,0) maps to Edm.Boolean &lt;/li&gt;        &lt;li&gt;EFOracle.number(5,0) maps to Edm.Int16 &lt;/li&gt;        &lt;li&gt;EFOracle.number(11,0) maps to Edm.Int32 &lt;/li&gt;        &lt;li&gt;EFOracle.raw(16) maps to Edm.Guid &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Here's the interesting piece of code taken from EFOracleProviderManifest.GetEdmType() that does it. It looks at facets attached to the given store type and translates certain combinations of them into mentioned EDM types.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;number&amp;quot;&lt;/span&gt;:
    {
        &lt;span class="kwrd"&gt;byte&lt;/span&gt; precision;
        &lt;span class="kwrd"&gt;byte&lt;/span&gt; scale;

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (MetadataHelpers.TryGetPrecision(storeType, &lt;span class="kwrd"&gt;out&lt;/span&gt; precision) &amp;amp;&amp;amp;
            MetadataHelpers.TryGetScale(storeType, &lt;span class="kwrd"&gt;out&lt;/span&gt; scale))
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (precision == 1 &amp;amp;&amp;amp; scale == 0)
                &lt;span class="kwrd"&gt;return&lt;/span&gt; TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Boolean));

            &lt;span class="kwrd"&gt;if&lt;/span&gt; (precision == 5 &amp;amp;&amp;amp; scale == 0)
                &lt;span class="kwrd"&gt;return&lt;/span&gt; TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int16));

            &lt;span class="kwrd"&gt;if&lt;/span&gt; (precision == 11 &amp;amp;&amp;amp; scale == 0)
                &lt;span class="kwrd"&gt;return&lt;/span&gt; TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));

            &lt;span class="kwrd"&gt;return&lt;/span&gt; TypeUsage.CreateDecimalTypeUsage(edmPrimitiveType, precision, scale);
        }
        &lt;span class="kwrd"&gt;else&lt;/span&gt;
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; TypeUsage.CreateDecimalTypeUsage(edmPrimitiveType);
        }
    }&lt;/pre&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Data type coercion in the data reader&lt;/strong&gt;. Data provider analyzes Canonical Query Tree (CQT) and remembers expected CLR types for each result column ordinal. Whenever this data type is different from the data returned by wrapped OracleDataReader, the value is coerced using Convert.ChangeType(). &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The code below extracts ExpectedColumnTypes from the canonical query tree:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;// Set expected column types for DbQueryCommandTree&lt;/span&gt;
DbQueryCommandTree queryTree = commandTree &lt;span class="kwrd"&gt;as&lt;/span&gt; DbQueryCommandTree;
&lt;span class="kwrd"&gt;if&lt;/span&gt; (queryTree != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
{
    DbProjectExpression projectExpression = queryTree.Query &lt;span class="kwrd"&gt;as&lt;/span&gt; DbProjectExpression;
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (projectExpression != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
    {
        EdmType resultsType = projectExpression.Projection.ResultType.EdmType;

        StructuralType resultsAsStructuralType = resultsType &lt;span class="kwrd"&gt;as&lt;/span&gt; StructuralType;
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (resultsAsStructuralType != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        {
            command.ExpectedColumnTypes = &lt;span class="kwrd"&gt;new&lt;/span&gt; PrimitiveType[resultsAsStructuralType.Members.Count];

            &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; ordinal = 0; ordinal &amp;lt; resultsAsStructuralType.Members.Count; ordinal++)
            {
                EdmMember member = resultsAsStructuralType.Members[ordinal];
                PrimitiveType primitiveType = member.TypeUsage.EdmType &lt;span class="kwrd"&gt;as&lt;/span&gt; PrimitiveType;
                command.ExpectedColumnTypes[ordinal] = primitiveType;
            }
        }
    }
}

&lt;span class="rem"&gt;// Set expected column types for DbFunctionCommandTree&lt;/span&gt;
DbFunctionCommandTree functionTree = commandTree &lt;span class="kwrd"&gt;as&lt;/span&gt; DbFunctionCommandTree;
&lt;span class="kwrd"&gt;if&lt;/span&gt; (functionTree != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
{
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (functionTree.ResultType != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
    {
        Debug.Assert(MetadataHelpers.IsCollectionType(functionTree.ResultType.EdmType),
            &lt;span class="str"&gt;&amp;quot;Result type of a function is expected to be a collection of RowType or PrimitiveType&amp;quot;&lt;/span&gt;);

        EdmType elementType = MetadataHelpers.GetElementTypeUsage(functionTree.ResultType).EdmType;

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (MetadataHelpers.IsRowType(elementType))
        {
            ReadOnlyMetadataCollection&amp;lt;EdmMember&amp;gt; members = ((RowType)elementType).Members;
            command.ExpectedColumnTypes = &lt;span class="kwrd"&gt;new&lt;/span&gt; PrimitiveType[members.Count];

            &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; ordinal = 0; ordinal &amp;lt; members.Count; ordinal++)
            {
                EdmMember member = members[ordinal];
                PrimitiveType primitiveType = (PrimitiveType)member.TypeUsage.EdmType;
                command.ExpectedColumnTypes[ordinal] = primitiveType;
            }

        }
        &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (MetadataHelpers.IsPrimitiveType(elementType))
        {
            command.ExpectedColumnTypes = &lt;span class="kwrd"&gt;new&lt;/span&gt; PrimitiveType[1];
            command.ExpectedColumnTypes[0] = (PrimitiveType)elementType;
        }
        &lt;span class="kwrd"&gt;else&lt;/span&gt;
        {
            Debug.Fail(&lt;span class="str"&gt;&amp;quot;Result type of a function is expected to be a collection of RowType or PrimitiveType&amp;quot;&lt;/span&gt;);
        }
    }
}&lt;/pre&gt;

&lt;p&gt;The provider needs to store this information in the DbCommand and pass down to DbDataReader. In the reader implementation, actual data coercion is done in the following manner:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; EFOracleDataReader : DbDataReader &lt;br /&gt;{
&lt;span class="kwrd"&gt;    private&lt;/span&gt; PrimitiveType[] _expectedColumnTypes;

&lt;span class="rem"&gt;    // ...&lt;/span&gt;

&lt;span class="kwrd"&gt;    public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; DateTime GetDateTime(&lt;span class="kwrd"&gt;int&lt;/span&gt; ordinal)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; (DateTime)GetValue(ordinal);
    }

&lt;span class="kwrd"&gt;    public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;decimal&lt;/span&gt; GetDecimal(&lt;span class="kwrd"&gt;int&lt;/span&gt; ordinal)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; (&lt;span class="kwrd"&gt;decimal&lt;/span&gt;)GetValue(ordinal);
    }

&lt;span class="kwrd"&gt;    public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; GetValue(&lt;span class="kwrd"&gt;int&lt;/span&gt; ordinal)
    {
        &lt;span class="kwrd"&gt;object&lt;/span&gt; rawValue = _oracleReader.GetValue(ordinal);

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (_expectedColumnTypes != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (!(rawValue &lt;span class="kwrd"&gt;is&lt;/span&gt; DBNull) &amp;amp;&amp;amp; rawValue.GetType()
                != _expectedColumnTypes[ordinal].ClrEquivalentType)
            {
                rawValue = ChangeType(rawValue, _expectedColumnTypes[ordinal].ClrEquivalentType);
            }
        }
        &lt;span class="kwrd"&gt;return&lt;/span&gt; rawValue;
    }

&lt;span class="kwrd"&gt;    private&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; ChangeType(&lt;span class="kwrd"&gt;object&lt;/span&gt; sourceValue, Type targetType)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (sourceValue &lt;span class="kwrd"&gt;is&lt;/span&gt; &lt;span class="kwrd"&gt;byte&lt;/span&gt;[] &amp;amp;&amp;amp; targetType == &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Guid))
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Guid((&lt;span class="kwrd"&gt;byte&lt;/span&gt;[])sourceValue);
        }
   
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (sourceValue &lt;span class="kwrd"&gt;is&lt;/span&gt; DateTime &amp;amp;&amp;amp; targetType == &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(DateTimeOffset))
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; DateTimeOffset((DateTime)sourceValue);
        }

        &lt;span class="kwrd"&gt;return&lt;/span&gt; Convert.ChangeType(sourceValue, targetType, CultureInfo.InvariantCulture);
    }

&lt;span class="rem"&gt;    // ...&lt;/span&gt;
}&lt;/pre&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Canonical Functions&lt;/strong&gt;. Most Canonical Functions required by Entity Framework have been implemented using Oracle's built-in functions. In some cases it required some query rewriting, such as when handling Right() canonical function which has no direct Oracle translation and SUBSTR() must be used instead. &lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; ISqlFragment HandleCanonicalFunctionRight(SqlGenerator sqlgen, DbFunctionExpression e)
{
    SqlBuilder result = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlBuilder();
    result.Append(&lt;span class="str"&gt;&amp;quot;(CASE WHEN LENGTH(&amp;quot;&lt;/span&gt;);
    result.Append(e.Arguments[0].Accept(sqlgen));
    result.Append(&lt;span class="str"&gt;&amp;quot;) &amp;gt;= (&amp;quot;&lt;/span&gt;);
    result.Append(e.Arguments[1].Accept(sqlgen));
    result.Append(&lt;span class="str"&gt;&amp;quot;) THEN &amp;quot;&lt;/span&gt;);
    result.Append(&lt;span class="str"&gt;&amp;quot;SUBSTR (&amp;quot;&lt;/span&gt;);
    result.Append(e.Arguments[0].Accept(sqlgen));
    result.Append(&lt;span class="str"&gt;&amp;quot;,-(&amp;quot;&lt;/span&gt;);
    result.Append(e.Arguments[1].Accept(sqlgen));
    result.Append(&lt;span class="str"&gt;&amp;quot;),&amp;quot;&lt;/span&gt;);
    result.Append(e.Arguments[1].Accept(sqlgen));
    result.Append(&lt;span class="str"&gt;&amp;quot;)&amp;quot;&lt;/span&gt;);
    result.Append(&lt;span class="str"&gt;&amp;quot; ELSE &amp;quot;&lt;/span&gt;);
    result.Append(e.Arguments[0].Accept(sqlgen));
    result.Append(&lt;span class="str"&gt;&amp;quot; END)&amp;quot;&lt;/span&gt;);
    &lt;span class="kwrd"&gt;return&lt;/span&gt; result;
}&lt;/pre&gt;

&lt;p&gt;Let me know if you have any questions about the EFOracleProvider release and EF provider interface in general.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8644126" width="1" height="1"&gt;</content><author><name>jkowalski</name><uri>http://blogs.msdn.com/members/jkowalski.aspx</uri></author><category term="Entity Framework" scheme="http://blogs.msdn.com/jkowalski/archive/tags/Entity+Framework/default.aspx" /><category term="EFSampleProvider" scheme="http://blogs.msdn.com/jkowalski/archive/tags/EFSampleProvider/default.aspx" /></entry><entry><title>EF Mapping Advisor</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jkowalski/archive/2008/06/05/ef-mapping-advisor.aspx" /><id>http://blogs.msdn.com/jkowalski/archive/2008/06/05/ef-mapping-advisor.aspx</id><published>2008-06-05T23:14:00Z</published><updated>2008-06-05T23:14:00Z</updated><content type="html">&lt;P&gt;&lt;A class="" href="http://blogs.msdn.com/juyik/" mce_href="http://blogs.msdn.com/juyik/"&gt;Ju-Yi Kuo&lt;/A&gt; from our team has started blogging about advanced mapping scenarios supported by Entity Framework.&lt;/P&gt;
&lt;P&gt;Part 1 of his EF Mapping Advisor series is online at &lt;A href="http://blogs.msdn.com/juyik/archive/2008/05/21/ef-mapping-advisor-1-the-language-of-mapping-part-a.aspx"&gt;http://blogs.msdn.com/juyik/archive/2008/05/21/ef-mapping-advisor-1-the-language-of-mapping-part-a.aspx&lt;/A&gt;&amp;nbsp;and it explains TPT (table-per-type) mapping strategy.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8576191" width="1" height="1"&gt;</content><author><name>jkowalski</name><uri>http://blogs.msdn.com/members/jkowalski.aspx</uri></author></entry><entry><title>Entity Framework Sample Provider for Visual Studio 2008 SP1 Beta is Online</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jkowalski/archive/2008/06/02/entity-framework-sample-provider-for-visual-studio-2008-sp1-beta-is-online.aspx" /><id>http://blogs.msdn.com/jkowalski/archive/2008/06/02/entity-framework-sample-provider-for-visual-studio-2008-sp1-beta-is-online.aspx</id><published>2008-06-03T08:48:00Z</published><updated>2008-06-03T08:48:00Z</updated><content type="html">&lt;P&gt;We have just published an updated&amp;nbsp;Sample ADO.NET Provider for Entity Framework.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Changes in the provider APIs since Beta3 release:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;removed DbProviderServices.GetProviderManifest(DbConnection)&lt;/LI&gt;
&lt;LI&gt;added DbProviderServices.GetProviderManifestToken(DbConnection)&lt;/LI&gt;
&lt;LI&gt;completely redesigned CSDL/SSDL/MSL for SchemaInformation&lt;/LI&gt;
&lt;LI&gt;changed the format of the provider manifest XML:&lt;BR&gt;&amp;nbsp;- DefaultValue vs Default&lt;BR&gt;&amp;nbsp;- removed facets from functions&lt;/LI&gt;
&lt;LI&gt;added DbProviderManifest.Token/DbProviderManifest.Provider properties&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Provider writers can get the source code from MSDN Code Gallery: &lt;U&gt;&lt;FONT color=#800080&gt;&lt;A href="http://code.msdn.microsoft.com/EFSampleProvider"&gt;http://code.msdn.microsoft.com/EFSampleProvider&lt;/A&gt;&lt;/FONT&gt;&lt;/U&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8571021" width="1" height="1"&gt;</content><author><name>jkowalski</name><uri>http://blogs.msdn.com/members/jkowalski.aspx</uri></author><category term="Entity Framework" scheme="http://blogs.msdn.com/jkowalski/archive/tags/Entity+Framework/default.aspx" /><category term="EFSampleProvider" scheme="http://blogs.msdn.com/jkowalski/archive/tags/EFSampleProvider/default.aspx" /></entry><entry><title>Transparent Lazy Loading for Entity Framework – part 3 – Anatomy of a Stub</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jkowalski/archive/2008/05/28/transparent-lazy-loading-for-entity-framework-part-3-anatomy-of-a-stub.aspx" /><id>http://blogs.msdn.com/jkowalski/archive/2008/05/28/transparent-lazy-loading-for-entity-framework-part-3-anatomy-of-a-stub.aspx</id><published>2008-05-28T19:11:00Z</published><updated>2008-05-28T19:11:00Z</updated><content type="html">&lt;p&gt;This post is a part of the series that describes &lt;a href="http://code.msdn.microsoft.com/EFLazyLoading" target="_blank" mce_href="http://code.msdn.microsoft.com/EFLazyLoading"&gt;EFLazyLoading&lt;/a&gt; library.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/jkowalski/archive/2008/05/12/transparent-lazy-loading-for-entity-framework-part-1.aspx" target="_blank" mce_href="http://blogs.msdn.com/jkowalski/archive/2008/05/12/transparent-lazy-loading-for-entity-framework-part-1.aspx"&gt;Part 1 - Strategies for implementing lazy loading&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/jkowalski/archive/2008/05/12/transparent-lazy-loading-for-entity-framework-part-2.aspx" target="_blank" mce_href="http://blogs.msdn.com/jkowalski/archive/2008/05/12/transparent-lazy-loading-for-entity-framework-part-2.aspx"&gt;Part 2 - Implementation of EFLazyLoading&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/jkowalski/archive/2008/05/28/transparent-lazy-loading-for-entity-framework-part-3-anatomy-of-a-stub.aspx" target="_blank" mce_href="http://blogs.msdn.com/jkowalski/archive/2008/05/28/transparent-lazy-loading-for-entity-framework-part-3-anatomy-of-a-stub.aspx"&gt;Part 3 - Anatomy of a Stub&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In two previous articles I have introduced EFLazyLoading &amp;#8211; a framework for lazy loading of entities on top of Entity Framework. In this post I will explain what stubs are and how they work. &lt;/p&gt;  &lt;p&gt;Let&amp;#8217;s establish some terminology first:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;Shell object&lt;/b&gt; is a public object that the users interact with. It has the properties of an entity, but no backing fields except for the primary key. &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Data object&lt;/b&gt; is an internal data structure that has backing fields for the object. It implements ILazyEntityDataObject interface. &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Stub object&lt;/b&gt; is a shell object that has no data object attached to it. &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Fully loaded&lt;/b&gt; &lt;b&gt;object&lt;/b&gt; is a shell that has a data object attached and populated. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Here is a typical pair of shell and data objects &amp;#8211; NorthwindEF.Category. Note a few things:&lt;a href="http://blogs.msdn.com/blogfiles/jkowalski/WindowsLiveWriter/d78d5e1ac24d_801B/image_2.png" mce_href="http://blogs.msdn.com/blogfiles/jkowalski/WindowsLiveWriter/d78d5e1ac24d_801B/image_2.png"&gt;&lt;img height="619" alt="Structure of the Category entity" src="http://blogs.msdn.com/blogfiles/jkowalski/WindowsLiveWriter/d78d5e1ac24d_801B/image_thumb.png" width="252" align="right" border="0" mce_src="http://blogs.msdn.com/blogfiles/jkowalski/WindowsLiveWriter/d78d5e1ac24d_801B/image_thumb.png" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;_CategoryID is the only field in the shell class (disregard the base class for a while). All other fields are declared in the data class &lt;/li&gt;    &lt;li&gt;The only public properties on the shell class are properties that correspond to EntityType definition. &lt;/li&gt;    &lt;li&gt;Data class is a nested type inside the shell class. &lt;/li&gt;    &lt;li&gt;Data class is a backing store for all non-key properties. &lt;/li&gt;    &lt;li&gt;Data objects must be able to deep-clone themselves. This is the purpose of ILazyEntityDataObject.Copy() method. &lt;/li&gt;    &lt;li&gt;Data properties (see previous article) are also declared in the Data class. This is because of pure convenience as it enables fields to be private. &lt;/li&gt;    &lt;li&gt;There are no public methods &amp;#8211; only protected CreateDataObject() which takes care of creating a private data object. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Shell objects implement ILazyEntityObject interface in addition to three IPOCO interfaces: IEntityWithKey, IEntityWithChangeTracking and IEntityWithRelationships. In current implementation those interfaces are implemented in the base class called LazyEntityObject.&lt;/p&gt;  &lt;p&gt;Data object in current implementation it is implemented as a class with fields, but in theory it could be implemented as a hash table (to allow for types with huge number of nullable columns that are often nulls) or in some other way.&lt;/p&gt;  &lt;h4&gt;How stubs are born&lt;/h4&gt;  &lt;p&gt;Stubs can come to life in four possible ways:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Relationship navigation &amp;#8211; when navigating a many-to-one relationship, a stub object is created to represent the related end (if the entity is not already being tracked by the ObjectStateManager). &lt;/li&gt;    &lt;li&gt;IQueryable&amp;lt;T&amp;gt;.AsStubs(). It is possible to construct a sequence of stubs (IEnumerable&amp;lt;T&amp;gt;) by calling AsStubs() on IQueryable&amp;lt;T&amp;gt;. This will convert a query to a query that only projects primary keys (thus saving on database connection bandwidth). &lt;/li&gt;    &lt;li&gt;IQueryable&amp;lt;T&amp;gt;.GetStub() that returns a single result. This is a stub equivalent of calling First(). &lt;/li&gt;    &lt;li&gt;It is also possible to populate LazyEntityCollection with stub objects (instead of fully loaded objects) by calling LoadStubs() method. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;There is also a way for unmodified fully loaded object to become stub again. All you have to do is to discard their data object by calling LazyObjectContext.Reset() or by calling LazyObjectContext.ResetAllUnchangedObjects() which does the same thing for all unmodified objects in the context. This can help reduce memory footprint of your unit of work, when you are dealing with large objects and you are done processing them. Instead of detaching an object from the context, you simply discard its data &amp;#8211; object identity is preserved and it can still be found in all relationships it belongs to, but most of objects memory can be reclaimed by GC.&lt;/p&gt;  &lt;h4&gt;Examples&lt;/h4&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;// instantiate a fully loaded entity&lt;/span&gt;
var prod = entities.Products.First();

&lt;span class="rem"&gt;// stub gets created because of relationship navigation - no load from the database here&lt;/span&gt;
var cat = prod.Category; 

&lt;span class="rem"&gt;// category object gets fully loaded on first property access&lt;/span&gt;
Console.WriteLine(&lt;span class="str"&gt;&amp;quot;name: {0}&amp;quot;&lt;/span&gt;, cat.CategoryName);

&lt;span class="rem"&gt;// once it is loaded we can access all properties - no database access here&lt;/span&gt;
Console.WriteLine(&lt;span class="str"&gt;&amp;quot;desc: {0}&amp;quot;&lt;/span&gt;, cat.Description);

&lt;span class="rem"&gt;// iterate through details&lt;/span&gt;
&lt;span class="rem"&gt;// note that collection is populated with LoadStubs which only brings keys&lt;/span&gt;
&lt;span class="rem"&gt;// into memory&lt;/span&gt;
&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (OrderDetail det &lt;span class="kwrd"&gt;in&lt;/span&gt; prod.OrderDetails.LoadStubs())
{
    &lt;span class="rem"&gt;// order can be Order or InternationalOrder so it will be eagerly loaded&lt;/span&gt;
    &lt;span class="rem"&gt;// because we don't know the concrete type (see below)&lt;/span&gt;
    &lt;span class="rem"&gt;// next time (even in a different ObjectContext) we'll use cached type information&lt;/span&gt;
    &lt;span class="rem"&gt;// so there's no server roundtrip&lt;/span&gt;
    var order = det.Order;

    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;{0} {1}&amp;quot;&lt;/span&gt;, det.Product.ProductName, order.OrderDate);
}

&lt;span class="rem"&gt;// execute a query and return collection of stub objects&lt;/span&gt;
var stubs = entities.Suppliers.Where(c =&amp;gt; c.Products.Any(d=&amp;gt;d.Category.CategoryID == cat.CategoryID)).AsStubs();

&lt;span class="rem"&gt;// iterate over stubs - as we go through the collection, individual suppliers are loaded on-demand&lt;/span&gt;
&lt;span class="kwrd"&gt;&lt;span class="rem"&gt;// note how LoadStubs() is used to count Products without fully loading them&lt;/span&gt;
foreach&lt;/span&gt; (var p &lt;span class="kwrd"&gt;in&lt;/span&gt; stubs)
{
    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Shipper {0} - {1} - {2} products&amp;quot;&lt;/span&gt;, p.CompanyName, p.Phone, p.Products.LoadStubs().Count);
}

&lt;span class="rem"&gt;// execute a query that returns a single stub object&lt;/span&gt;
var singleStub = entities.Suppliers.GetStub(c=&amp;gt;c.SupplierID == 4);
Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Stub: {0}&amp;quot;&lt;/span&gt;, singleStub.Phone);&lt;/pre&gt;

&lt;h4&gt;Problem with polymorphic types&lt;/h4&gt;

&lt;p&gt;Despite our intention, we sometimes get fully loaded objects instead of stubs when calling one of the above methods &amp;#8211; that is because of polymorphic types. For example, when your schema has a Customer base type and InternationalCustomer type derived from and there is an association from Order to Customer, you can get either a customer or international customer when you navigate the association:&lt;/p&gt;

&lt;p&gt;We cannot possibly know the concrete type up front by examining its EntityKey. Unfortunately to create a stub/shell object we need to know the CLR type. When doing eager load, Entity Framework materializer takes care of determining concrete type by sending a specially crafted SQL query down to the server. The query includes a special discriminator column down which is used to resolve back to concrete type. Unfortunately in this case we don&amp;#8217;t want to send any query. Even if we wanted to do that, neither Entity SQL nor LINQ have a way to project object type without loading full object, so store cannot really help us here.&lt;/p&gt;

&lt;h4&gt;Enter IObjectTypeCache&lt;/h4&gt;

&lt;p&gt;IObjectTypeCache is one proposed solution to this problem. It exploits the fact, that (using normal methods) objects never change their type &amp;#8211; there is no way to change the class of an entity stored in a database table, because Entity Framework does not allow inheritance discriminator columns (in TPH mapping) to be written to and there is no way to achieve the same thing in case of TPT or TPC mappings.&lt;/p&gt;

&lt;p&gt;IObjectTypeCache s a cache whose keys are EntityKey objects and values are CLR types (in fact they are factory methods that return objects). This gives us amortized low cost of determining the type given a CLR type.&lt;/p&gt;

&lt;p&gt;Every time we create a stub (of type T), we check whether the EntityType has subclasses (defined in CSDL). If the type is known to not to be polymorphic, we just create a new instance of T.&lt;/p&gt;

&lt;p&gt;If the type can have subclasses, we check whether the mapping from EntityKey to type is found in cache &amp;#8211; if it is there &amp;#8211; we just call the factory method and the stub is ready.&lt;/p&gt;

&lt;p&gt;If the mapping is not found in the cache (which typically happens the first time a particular EntityKey is materialized in an application), we don&amp;#8217;t try to create stubs at all &amp;#8211; we fall back to running the fully materialized query which resolves the type for us. After this is done, we add newly discovered key-to-type mappings to our cache, so that the mappings are known next time.&lt;/p&gt;

&lt;p&gt;There is a singleton object that holds a reference to IObjectTypeCache that all LazyObjectContexts will use &amp;#8211; it is currently held in a static property of LazyObjectContext called ObjectTypeCache.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;b&gt;WARNING: &lt;/b&gt;The default implementation of IObjectTypeCache (as of EFLazyLoading v0.5) does not do any cache eviction. This is typically not a problem for databases that have about one million of polymorphic objects (cache can grow up to consume 30-50MB of RAM which is usually not a problem nowadays). If your application has to scale to support more polymorphic objects than that, the sample has to be modified to add some automatic eviction (based on LRU, LFU or other strategy).&lt;/p&gt;&lt;/blockquote&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8556704" width="1" height="1"&gt;</content><author><name>jkowalski</name><uri>http://blogs.msdn.com/members/jkowalski.aspx</uri></author><category term="Entity Framework" scheme="http://blogs.msdn.com/jkowalski/archive/tags/Entity+Framework/default.aspx" /><category term="EFLazyLoading" scheme="http://blogs.msdn.com/jkowalski/archive/tags/EFLazyLoading/default.aspx" /></entry></feed>