<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">

<channel>
	<title>Living in the Tech Avalanche Generation</title>
	<atom:link href="http://www.simonsegal.net/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.simonsegal.net/blog</link>
	<description>A practitioner's introspective on technology</description>
	<pubDate>Fri, 12 Mar 2010 11:07:40 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
	<creativeCommons:license>http://creativecommons.org/licenses/by-sa/2.5/au/</creativeCommons:license>		<item>
		<title>Are we not men - we are Devo?</title>
		<link>http://www.simonsegal.net/blog/2010/03/12/are-we-not-men-we-are-devo/</link>
		<comments>http://www.simonsegal.net/blog/2010/03/12/are-we-not-men-we-are-devo/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 11:03:05 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[Career]]></category>

		<category><![CDATA[developers]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/03/12/are-we-not-men-we-are-devo/</guid>
		<description><![CDATA[ 
Does this look like you? Are you surrounded by like minded individuals, sharing a community experience at work with your fellow geeks? Perhaps you have even gone further than that and made a lasting friend or two out of your fellow developers. That certainly describes&#160; the kind of environment that I flourish in and [...]<p><a href="http://www.simonsegal.net/blog/2010/03/12/are-we-not-men-we-are-devo/">Are we not men - we are Devo?</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/03/image2.png"><img style="border-right-width: 0px; margin: 0px 5px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="left" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/03/image-thumb2.png" width="151" height="167" /></a> </p>
<p>Does this look like you? Are you surrounded by like minded individuals, sharing a community experience at work with your fellow geeks? Perhaps you have even gone further than that and made a lasting friend or two out of your fellow developers. That certainly describes&#160; the kind of environment that I flourish in and in my more senior years, have worked hard to foster. It’s my experience that software developed in this environment is more cohesive and easier to maintain over the long haul. With he right personality types, social activity at work for geeks&#160; often means talking shop and this leads to a win – win situation for everyone. More ideas begat better ideas, common work patterns begin to evolve; other than that it’s just plain more enjoyable.</p>
<p>However I have struck the odd workplace that is the antithesis of what I have just described. Personality bereft work silos, with dead silence abounding throughout the organisation, lack of willingness to work together, fostering a cycle of suspicion and loss of preparedness to work as a team. I have seen enough of this type of work place to know that I can never work in one again.</p>
<p>Of course it’s possible that I have just described your workplace and perhaps even worse than that, it’s the way it is because you designed it to be that way? What kind of work environment do you have? Do the developers at your office communicate with one another vibrantly, rich in tone and timbre, taking coffee breaks together, occasionally going out for lunch and generally taking any office bound social opportunity to debate and discuss geeky things? Do you have a mate at work? </p>
<p>I would really be interested to hear the arguments (if there are any) that make a case for this almost <a href="http://en.wikipedia.org/wiki/Bertolt_Brecht">Brechtian</a> bleakness and minimalism in surroundings.</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=Are%20we%20not%20men%20-%20we%20are%20Devo%3F&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F03%2F12%2Fare-we-not-men-we-are-devo%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Are we not men - we are Devo?";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/03/12/are-we-not-men-we-are-devo/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/03/12/are-we-not-men-we-are-devo/">Are we not men - we are Devo?</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/03/12/are-we-not-men-we-are-devo/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ADSD Course with Udi Dahan in Sydney Australia for November 2010</title>
		<link>http://www.simonsegal.net/blog/2010/03/04/adsd-course-with-udi-dahan-in-sydney-australia-for-november-2010/</link>
		<comments>http://www.simonsegal.net/blog/2010/03/04/adsd-course-with-udi-dahan-in-sydney-australia-for-november-2010/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 06:50:04 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[DDD]]></category>

		<category><![CDATA[Distributed]]></category>

		<category><![CDATA[NServiceBus]]></category>

		<category><![CDATA[Training]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/03/04/adsd-course-with-udi-dahan-in-sydney-australia-for-november-2010/</guid>
		<description><![CDATA[ Hot on the heels of Udi’s visit to Melbourne this year (in January), comes another chance to make good if you missed out. Plans are underway for Udi to visit us yet again, this time in Sydney. If your interested check out Udi’s post and register your interest using the link for the proposed [...]<p><a href="http://www.simonsegal.net/blog/2010/03/04/adsd-course-with-udi-dahan-in-sydney-australia-for-november-2010/">ADSD Course with Udi Dahan in Sydney Australia for November 2010</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/03/image1.png"><img style="border-bottom: 0px; border-left: 0px; margin: 0px 5px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/03/image-thumb1.png" width="157" height="75" /></a> Hot on the heels of Udi’s <a href="http://www.simonsegal.net/blog/guests-on-demand/">visit to Melbourne</a> this year (in January), comes another chance to make good if you missed out. Plans are underway for Udi to visit us yet again, this time in Sydney. If your interested check out Udi’s <a href="http://www.udidahan.com/2010/03/01/nservicebus-2-0-rtm/">post</a> and register your interest using the link for the proposed Sydney event. If you want to know more about the course you can see the course outline <a href="http://www.udidahan.com/training/">here</a> and read <a href="http://www.simonsegal.net/blog/2010/02/04/adsd-nservicebus-and-nuclear-armament-the-full-story/">my review</a> which contains links to some further reviews from other attendees in Melbourne earlier this year.</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=ADSD%20Course%20with%20Udi%20Dahan%20in%20Sydney%20Australia%20for%20November%202010&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F03%2F04%2Fadsd-course-with-udi-dahan-in-sydney-australia-for-november-2010%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="ADSD Course with Udi Dahan in Sydney Australia for November 2010";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/03/04/adsd-course-with-udi-dahan-in-sydney-australia-for-november-2010/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/03/04/adsd-course-with-udi-dahan-in-sydney-australia-for-november-2010/">ADSD Course with Udi Dahan in Sydney Australia for November 2010</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/03/04/adsd-course-with-udi-dahan-in-sydney-australia-for-november-2010/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Helping Entity Framework v4.0 play it&#8217;s &#60;ROLE&#62; &#8211; Part 3.0</title>
		<link>http://www.simonsegal.net/blog/2010/02/21/helping-entity-framework-v40-play-its-role-part-30/</link>
		<comments>http://www.simonsegal.net/blog/2010/02/21/helping-entity-framework-v40-play-its-role-part-30/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 11:33:23 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[DDD]]></category>

		<category><![CDATA[Entity Framework]]></category>

		<category><![CDATA[Patterns &amp; Practices]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/02/21/helping-entity-framework-v40-play-its-role-part-30/</guid>
		<description><![CDATA[In part 1.0 we laid the foundation and part 2.0 unravelled some of the internal details of how NFetchSpec (the libraries that are subject of this discussion) goes about enlisting the benefits that can be derived by using explicit roles in your system by collapsing a swathe of Entity Framework functionality into a somewhat compact [...]<p><a href="http://www.simonsegal.net/blog/2010/02/21/helping-entity-framework-v40-play-its-role-part-30/">Helping Entity Framework v4.0 play it&rsquo;s &lt;ROLE&gt; &ndash; Part 3.0</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.simonsegal.net/blog/2010/01/04/helping-entity-framework-v40-play-its-role-part-10/">part 1.0</a> we laid the foundation and <a href="http://www.simonsegal.net/blog/2010/02/17/helping-entity-framework-v40-play-its-role-part-20/">part 2.0</a> unravelled some of the internal details of how NFetchSpec (the libraries that are subject of this discussion) goes about enlisting the benefits that can be derived by using explicit roles in your system by collapsing a swathe of Entity Framework functionality into a somewhat compact approach to dealing with a Domain Model. First a quick recap of the underpinnings.</p>
<h3><span style="text-decoration: underline">Figure 1.0</span></h3>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/ef-roles-part3-nfetch-in-action-usage-quadrant.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ef_roles_part3_nfetch_in_action_usage_quadrant" border="0" alt="ef_roles_part3_nfetch_in_action_usage_quadrant" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/ef-roles-part3-nfetch-in-action-usage-quadrant-thumb.png" width="490" height="413" /></a></p>
<h4><span style="text-decoration: underline">Code from Figure 1.0</span></h4>
<p><span style="text-decoration: underline"></span></p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> resolves_everything_from_container()
{
    IList&lt;IRunOutDiscountForProducts&gt; products = <span style="color: #0000ff">null</span>;

    var compParams = <span style="color: #0000ff">new</span> Dictionary&lt;<span style="color: #0000ff">string</span>, <span style="color: #0000ff">string</span>&gt;();
    compParams.Add(_conParamName, _connectionStringOnly);

    var repo = FetchSpec.Configure
                            .With(<span style="color: #0000ff">new</span> IoC())
                            .AndBuildSession&lt;IRunOutDiscountForProducts&gt;
                                (compParams)
                            .ForRepository();

    <span style="color: #0000ff">using</span> (var scope = <span style="color: #0000ff">new</span> TransactionScope(TransactionScopeOption.Required,
        <span style="color: #0000ff">new</span> TransactionOptions()
        {
            IsolationLevel =
                SessionBuilder&lt;IRunOutDiscountForProducts&gt;.ScopeIsolation()
        }))
    {
        products = repo.Get&lt;IRunOutDiscountForProducts&gt;();
        <span style="color: #0000ff">foreach</span> (var product <span style="color: #0000ff">in</span> products)
        {
            product.DiscountProductForRunOut();
        }

        scope.Complete();
    }
}</pre>
</div>
<p>Figure 1.0 demonstrates how all the moving parts in the developer experience are put to use when using the NFetchSpec libraries to query and make changes to a persisted Domain Model. Let’s now examine in detail all the steps that make up the entire developer experience of composing all the discrete pieces needed in addressing the role of <strong><em>IRunOutDiscountForProducts</em></strong> (in our fictitious system).</p>
<h2><span style="text-decoration: underline">The Development Scenario</span></h2>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/image.png" target="_blank"><img style="border-right-width: 0px; margin: 0px 5px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="left" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/image-thumb.png" width="37" height="38" /></a> The first outlined section in figure 1.0 demonstrates the building of an appropriate ObjectContext for the Repository that is instantiated by the fluent interface. From the developer experience perspective, nothing special needs to be done outside of specifying the role to the fluent interface in this manner.</p>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/image1.png" target="_blank"><img style="border-right-width: 0px; margin: 0px 5px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="left" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/image-thumb1.png" width="37" height="38" /></a> The second outlined section in figure 1.0 highlights how the role is leveraged to dynamically have NFetchSpec chose the ‘<strong>right</strong>’ isolation level. Being explicit in this way we can achieve a high degree of separation of concerns with respect to transaction isolation and thus exercise our control over the concurrency and throughput in the database on a role by role basis. In the example, we are discounting products earmarked for a run out sale, consequently changing their unit price, therefore we might like to choose a higher isolation level for that particular operation, depending on the volatility of the data that your dealing with and the normalization or lack thereof in your database schema. For the developer this means creating a concrete implementation of the interface <strong><em>IProvideIsolationLevelFor&lt;T&gt;</em></strong>, to support this automagic behaviour.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> interface IProvideIsolationLevelFor&lt;TRole&gt;
{
    IsolationLevel GetScopeIsolationForRole { <span style="color: #0000ff">get</span>;}
}

<span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> RunoutDiscountIsolation :
             IProvideIsolationLevelFor&lt;IRunOutDiscountForProducts&gt;
{
    <span style="color: #0000ff">public</span> IsolationLevel GetScopeIsolationForRole
    {
        <span style="color: #0000ff">get</span> { <span style="color: #0000ff">return</span> IsolationLevel.ReadCommitted; }
    }
}</pre>
</div>
<p>That’s it as far as getting your transaction set for the right Isolation Level within the scope of work for a given role. If we decide at some point that this Isolation Level is not the best fit, we can replace it with a new implementation.</p>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/image2.png" target="_blank"><img style="border-right-width: 0px; margin: 0px 5px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="left" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/image-thumb2.png" width="37" height="38" /></a> The Third outlined section in figure 1.0 highlights the use of the Repository to retrieve the Entities that we are interested in. This is where the NFetchSpec machinery goes to work to resolve all the purpose built artefacts that have been implemented for the given role, such as any applicative Fetching Strategy, Specification, Entity and Mapping.</p>
<h3><span style="text-decoration: underline">The Loaded Fetching Strategy</span></h3>
<p><span style="text-decoration: underline"></span></p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ProductRunOutFetchingStrategy :
             FetchingStrategy&lt;IRunOutDiscountForProducts&gt;
{
    <span style="color: #0000ff">public</span> ProductRunOutFetchingStrategy()
        : base(<span style="color: #0000ff">false</span>)
    {
        var production_intentions =
            EagerFetchingIntention
            .CreateInstance&lt;IRunOutDiscountForProducts,
                            ISupplier&gt;(p =&gt; p.Supplier);

        this.AddIntentions(<span style="color: #0000ff">new</span> IEagerFetchingIntention[]
        {
            production_intentions
        });
    }
}</pre>
</div>
<p>The intent of the developer in building this Fetching Strategy is to load Products eagerly with their reference Supplier.</p>
<h3><span style="text-decoration: underline">The Loaded Specification</span></h3>
<p><span style="text-decoration: underline"></span></p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> RunOutProductDiscountSpecification :
             Specification&lt;IRunOutDiscountForProducts&gt;
{
    <span style="color: #0000ff">public</span> RunOutProductDiscountSpecification()
        : base(p =&gt; p.UnitPrice &gt; 5M &amp;&amp; p.Supplier.Region == &quot;London&quot;) { }
}</pre>
</div>
<p>The Specification is really quite simple and self evident – setting up the applicative Expression that will ultimately be translated into a ‘where’ predicate.</p>
<h3><span style="text-decoration: underline">The Loaded Mapping</span></h3>
<p>First up we need to map our Entities and that requires a Mapping&lt;T&gt;.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ProductMapping : Mapping&lt;Product&gt;
{
    <span style="color: #0000ff">public</span> ProductMapping(string objectSetName) : base(objectSetName)
    {
        Property(p =&gt; p.ProductID).IsIdentity();
        Property(p =&gt; p.ProductName).HasMaxLength(50).IsRequired();
        Property(p =&gt; p.UnitPrice).<span style="color: #0000ff">Precision</span> = 19;
        Property(p =&gt; p.UnitPrice).Scale = 4;
        Relationship(p =&gt; p.Supplier).IsOptional();
        Relationship(p =&gt; p.Supplier).IsOptional().FromProperty(s =&gt; s.Products);
    }
}</pre>
</div>
<p>And because our example has a reference Entity in the root we require the following <strong><em>Supplier</em></strong> Entity Mapping also.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> SupplierMapping : Mapping&lt;Supplier&gt;
{
    <span style="color: #0000ff">public</span> SupplierMapping(string objectSetName)
        : base(objectSetName)
    {
        Property(s =&gt;  s.SupplierID).IsIdentity();
        Property(s =&gt; s.CompanyName).HasMaxLength(40).IsRequired();
        Property(s =&gt; s.Region).HasMaxLength(15);
        Relationship(s =&gt; s.Products).IsOptional().FromProperty(p =&gt; p.Supplier);
    }
}</pre>
</div>
<p>The last requirement of the developer with respect to mapping is to create a MappingRole&lt;T&gt;, the purpose of which is to indicate to the infrastructure which mappings are applicable to the Role.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> RunOutDiscountMappingRole :
             IMappingRole&lt;IRunOutDiscountForProducts&gt;
{
    private IMapping[] _mappings;

    <span style="color: #0000ff">public</span> RunOutDiscountMappingRole()
    {
        _mappings = <span style="color: #0000ff">new</span> IMapping[]
                    {
                        <span style="color: #0000ff">new</span> ProductMapping(&quot;Products&quot;),
                        <span style="color: #0000ff">new</span> SupplierMapping(&quot;Suppliers&quot;)
                    };
    }

    <span style="color: #0000ff">public</span> IMapping[] Mappings
    {
        <span style="color: #0000ff">get</span> { <span style="color: #0000ff">return</span> _mappings; }
    }
}</pre>
</div>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/image3.png" target="_blank"><img style="border-right-width: 0px; margin: 0px 5px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="left" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/image-thumb3.png" width="37" height="38" /></a> The fourth and final outlined section in figure 1.0 is really the essence of what is going on here, it is entirely the reason this code is being invoked – it is the purpose (discounting products) of the system for this role. When developing in this way we need to specify the behaviour of the Role through the stable abstraction of it’s interface, and implement that behaviour in a concrete Entity.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> interface IRunOutDiscountForProducts : IProductData
{
    void DiscountProductForRunOut();
}</pre>
</div>
<p><span style="text-decoration: underline"></span></p>
<h2><span style="text-decoration: underline">The Bang and Crash</span></h2>
<p>So with all that done, we need to deploy our “Role inspired” artefacts to the executing processes assemblies folder and when it’s all said and done the code from Figure 1.0 executes, enlisting the service of NFetchSpec in applying the combined intent and customised behaviours described in all of the deployed pieces.</p>
<p>From the database perspective, SQL Profiler tells us that our intent for this ROLE has been met and the system has behaved precisely as expected.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">SELECT</span>
    [Extent1].[ProductID] <span style="color: #0000ff">AS</span> [ProductID],
    [Extent1].[ProductName] <span style="color: #0000ff">AS</span> [ProductName],
    [Extent1].[UnitPrice] <span style="color: #0000ff">AS</span> [UnitPrice],
    [Extent1].[SupplierID] <span style="color: #0000ff">AS</span> [SupplierID]
<span style="color: #0000ff">FROM</span>
    [dbo].[Products] <span style="color: #0000ff">AS</span> [Extent1]
<span style="color: #0000ff">INNER</span> <span style="color: #0000ff">JOIN</span>
    [dbo].[Suppliers] <span style="color: #0000ff">AS</span> [Extent2]
<span style="color: #0000ff">ON</span>
    [Extent1].[SupplierID] = [Extent2].[SupplierID]
<span style="color: #0000ff">WHERE</span>
    ([Extent1].[UnitPrice] &lt; <span style="color: #0000ff">cast</span>(20 <span style="color: #0000ff">as</span> <span style="color: #0000ff">decimal</span>(18)))
<span style="color: #0000ff">AND</span>
    (N<span style="color: #006080">&#8216;London&#8217;</span> = [Extent2].[Region])</pre>
</div>
<p>We can see that Fetching Strategy and Specification have been successful in shaping the TSQL sent to the server to retrieve the data. Below we can also see the effect of applying the business rules through our Domain Model.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">exec</span> sp_executesql N<span style="color: #006080">&#8216;update [dbo].[Products]
set [UnitPrice] = @0
where ([ProductID] = @1)
&#8216;</span>,N<span style="color: #006080">&#8216;@0 decimal(19,4),@1 int&#8217;</span>,@0=3.2960,@1=1</pre>
</div>
<p><span style="text-decoration: underline"></span></p>
<h2><span style="text-decoration: underline">Just one more thing</span></h2>
<p>Part 4.0 will be the final part in the series and will focus on how this approach blends into a service layer in a Service Oriented Architecture and also make the code for NFetchSpec available for download.</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=Helping%20Entity%20Framework%20v4.0%20play%20it%26rsquo%3Bs%20%3CROLE%3E%20%26ndash%3B%20Part%203.0&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F02%2F21%2Fhelping-entity-framework-v40-play-its-role-part-30%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Helping Entity Framework v4.0 play it&rsquo;s <ROLE> &ndash; Part 3.0";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/02/21/helping-entity-framework-v40-play-its-role-part-30/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/02/21/helping-entity-framework-v40-play-its-role-part-30/">Helping Entity Framework v4.0 play it&rsquo;s &lt;ROLE&gt; &ndash; Part 3.0</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/02/21/helping-entity-framework-v40-play-its-role-part-30/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Doing .NET Days March 6th Fully Booked.</title>
		<link>http://www.simonsegal.net/blog/2010/02/18/doing-net-days-march-6th-fully-booked/</link>
		<comments>http://www.simonsegal.net/blog/2010/02/18/doing-net-days-march-6th-fully-booked/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 14:13:00 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[doing .Net Days]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/02/17/doing-net-days-march-6th-fully-booked/</guid>
		<description><![CDATA[ Doing .Net Days for March 6th 2010 is now fully booked. Thanks to all those who have registered. It’s becoming apparent that the current venue may not be large enough to accommodate the interest moving forward so we are exploring alternative venues and will keep you up date as news comes to hand.
We are [...]<p><a href="http://www.simonsegal.net/blog/2010/02/18/doing-net-days-march-6th-fully-booked/">Doing .NET Days March 6th Fully Booked.</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/20pc-black1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="20pc_black" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/20pc-black-thumb1.png" border="0" alt="20pc_black" width="96" height="81" align="left" /></a> Doing .Net Days for March 6th 2010 is now <a href="http://www.simonsegal.net/blog/training/">fully booked</a>. Thanks to all those who have registered. It’s becoming apparent that the current venue may not be large enough to accommodate the interest moving forward so we are exploring alternative venues and will keep you up date as news comes to hand.</p>
<p>We are also in the throws of putting together the web site for the event which will be announce shortly.</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=Doing%20.NET%20Days%20March%206th%20Fully%20Booked.&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F02%2F18%2Fdoing-net-days-march-6th-fully-booked%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Doing .NET Days March 6th Fully Booked.";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/02/18/doing-net-days-march-6th-fully-booked/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/02/18/doing-net-days-march-6th-fully-booked/">Doing .NET Days March 6th Fully Booked.</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/02/18/doing-net-days-march-6th-fully-booked/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Helping Entity Framework v4.0 play it&#8217;s &#60;ROLE&#62; - Part 2.0</title>
		<link>http://www.simonsegal.net/blog/2010/02/17/helping-entity-framework-v40-play-its-role-part-20/</link>
		<comments>http://www.simonsegal.net/blog/2010/02/17/helping-entity-framework-v40-play-its-role-part-20/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 01:53:59 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[DDD]]></category>

		<category><![CDATA[Entity Framework]]></category>

		<category><![CDATA[Patterns &amp; Practices]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/02/17/helping-entity-framework-v40-play-its-role-part-20/</guid>
		<description><![CDATA[The content of this series of posts is based around a spiking effort / proof of concept that aims to modularize (I am avoiding the word framework) a set of libraries for the express purpose of addressing business intent for Domain models persisted with the Entity Framework. In part 1.0 we laid the groundwork and [...]<p><a href="http://www.simonsegal.net/blog/2010/02/17/helping-entity-framework-v40-play-its-role-part-20/">Helping Entity Framework v4.0 play it&rsquo;s &lt;ROLE&gt; - Part 2.0</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p>The content of this series of posts is based around a spiking effort / proof of concept that aims to modularize (I am avoiding the word framework) a set of libraries for the express purpose of addressing business intent for Domain models persisted with the Entity Framework. In <a href="http://www.simonsegal.net/blog/2010/01/04/helping-entity-framework-v40-play-its-role-part-10/">part 1.0</a> we laid the groundwork and now we dig deeper.</p>
<p>I’m going to start this post at the end and then rewind all the way to beginning and step through how we got here. Here is some code that will return a list of products and in so doing, will dynamically determine the correct Entity type to return (a Product), will eagerly fetch their reference supplier and will apply a ‘where’ predicate to the LINQ To Entities query. All this will happen out of clear view as a result of being explicit and specifying a role / interface to the ORM when we ask it do something.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> Some_Method_In_My_Service_Layer
{
    var products = Repository.Get&lt;IRunOutDiscountForProducts&gt;();
}</pre>
</div>
<p>Now let’s briefly forget we saw this code and go back to the start.</p>
<p>Lets start by imagining some simple data access code that’s enormously compact and equally deceptive in it’s apparent simplicity. For a scenario, let’s propose that we want to get all the products in our system that are eligible for applying a run out discount. The business logic in achieving this function, specifies that a Products Unit Price Price  be greater 20.50 dollars and is purchased from suppliers in a given enumerable list of regions. For the sake of the example we will also say that this would require a Product entity and Supplier Entity in the following relationship.</p>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/product-supplier-class-diag.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="product_supplier_class_diag" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/product-supplier-class-diag-thumb.png" border="0" alt="product_supplier_class_diag" width="447" height="253" /></a></p>
<p>So given our the scenario we would be required to map the Entities appropriately, choose an appropriate method of loading (lazy or eager) and apply a suitable predicate to the SQL query. Let’s now imagine that by specifying a role (in this case the interface <strong><em>IRunOutDiscountForProducts</em></strong>), that we have provided the infrastructure code enough information to query the database for products and do so in a way that meets the proposed scenario requirements enumerated above.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">var conParams = <span style="color: #0000ff;">new</span> Dictionary&lt;<span style="color: #0000ff;">string</span>, <span style="color: #0000ff;">string</span>&gt;();
conParams .Add(_conParamName, _connectionStringOnly);

var repository = FetchSpec.Configure
                    .With(<span style="color: #0000ff;">new</span> StubIoc()
                        { ScannedAssemblyPath = _scannedAssemblyPath })
                    .AndBuildSession&lt;IRunOutDiscountForProducts&gt;(conParams)
                    .ForRepository();

var products = repository.Get&lt;IRunOutDiscountForProducts&gt;();</pre>
</div>
<p>The line of code that interests us most at this point is the last one. By applying the role of <strong><em>IRunOutDiscountForProducts </em></strong>to the GET&lt;T&gt; function<strong><em>,</em></strong> we are able to indicate to the infrastructure that our intent is to retrieve a list of Products for the express reason to apply a ‘run out’ discount to them. The next line of code you might expect to see would logically be something like:</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">products = repo.Get&lt;IRunOutDiscountForProducts&gt;();
<span style="color: #0000ff;">foreach</span> (var product <span style="color: #0000ff;">in</span> products)
{
    product.DiscountProductForRunOut();
}

repo.Save();</pre>
</div>
<p>What figure 1.0 shows is that we would like our Repository to be smart enough to know exactly what and how to fetch based on the role (the generic parameterized interface).</p>
<h3><span style="text-decoration: underline;">Figure 1.0</span></h3>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/explicit-concerns.gif" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="explicit_concerns" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/explicit-concerns-thumb.gif" border="0" alt="explicit_concerns" width="448" height="208" /></a></p>
<p>I promise we will get to the end soon enough but bear with me for a minute or two. One thing about being explicit with roles, it makes understanding code all the more simple. The less ambiguity the less likely someone misunderstands intent. In the realm of software development the humble interface (not the UI kind) has carried the torch ably in helping us declare our intent more explicitly, make our code better understood and free of concrete dependencies / coupling. With reverence and honour for my past (COM programming veteran status), I apologise in advance for the ubiquitous IDog example but it makes a point.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> Poodle : IDog
{
    <span style="color: #008000;">//&#8230;.etc</span>
}</pre>
</div>
<p>Explicitly a Poodle must now conform polymorphically et al to the contract specified by IDog – real 101 stuff no doubt. What about a marker interface? True enough, a very useful construct, bereft of polymorphic intent and largely a utility to express membership to a conceptual entity group of some kind, often put to use in frameworks to support dynamism of some description. Let’s use an NServiceBus IMessage as an example:</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">interface</span> IMessage {}

<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> OrderCancelledMessage : IMessage
{
    <span style="color: #008000;">//&#8230;.etc</span>
}</pre>
</div>
<p>Without going too deep into this at a code level, suffice to say that the NServiceBus infrastructure will behave in certain ways when it comes across types that implement the IMessage interface, in other words the framework is directing us to ‘mark’ a given class (or interface) as being recognizable as a ‘Message’, making it identifiable to the frameworks internal workings.</p>
<p>The virtues of programming by interface are now well documented and for .NET developers the advent and popularity of generics has encouraged our creativity in placing stable abstractions  around things to make code more explicit. For example, a while back I wrote in the abstract on the use of interfaces to define roles; roles describe the polymorphic nature of a business domain command and arguably event. This series of posts is an extension of <a href="http://www.simonsegal.net/index.php?s=roles&amp;sbutt=Go">those made in the past</a>, the focus however now moves to a proof of concept for the up coming Entity Framework 4.0.</p>
<h3><span style="text-decoration: underline;">What is a Role?</span></h3>
<p>Roles identify or describe commands / behaviours in the domain, an level of intent that can be be nicely defined by an interface.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">interface</span> IRunOutDiscountForProducts : IProductData
{
    <span style="color: #0000ff;">void</span> DiscountProductForRunOut();
}</pre>
</div>
<p>We can use these roles (interfaces) to indicate to our infrastructure (an ORM in this case) what our intent is and have the infrastructure behave appropriately based on configuration and / or convention.</p>
<p>Since we started with an example that focused around products, lets continue with that subject for a moment. It may be that my system needs to fetch Products for a variety of reasons and not always with the same intent. We shouldn’t be asking for a generic list of Products, considering that we are interested in them with a very specific context in mind and its the context determines the behaviour and describes the a role.</p>
<p>Once our system becomes explicit in this way through the use of roles in our domain, we can do some interesting things. We can instruct the ORM how to load the entity graph by implementing Fetching Strategies, dynamically resolve the most appropriate Entity Mapping to use and which predicate to apply to the query for the purpose of business logic filtering. Not only does the the role provide a stable abstraction, it insulates other parts of the architecture, perhaps a service layer or controller, from changes, allowing the actors to vary independently.</p>
<h3><span style="text-decoration: underline;">The Roles Quadrant:</span></h3>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/quadrant-roles.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="quadrant_roles" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/quadrant-roles-thumb.png" border="0" alt="quadrant_roles" width="456" height="212" /></a></p>
<p>Whilst working on this proof of concept in my attempts at cajoling the Entity Framework to work in this fashion, it became evident that there were four main pieces of the puzzle, Fetching Strategies, Specifications, Mapping, and Repositories. One thing that I haven’t mentioned yet, is the effect on concurrency, scale and throughput that this approach can have. Through the use of roles we can plug into the architecture yet again and explicitly pick an isolation level for the operation at hand.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff;">using</span> (var scope = <span style="color: #0000ff;">new</span> TransactionScope(TransactionScopeOption.Required,
    <span style="color: #0000ff;">new</span> TransactionOptions()
    {
        IsolationLevel =
            SessionBuilder&lt;IRunOutDiscountForProducts&gt;.ScopeIsolation()
    }))
{
    <span style="color: #008000;">//&#8230;..do some stuff here like load data </span>
    <span style="color: #008000;">//&#8230;..change data by calling into your domain model</span>
    <span style="color: #008000;">//&#8230;..and finally save the changes</span>

    scope.Complete();
}</pre>
</div>
<p>Notice that in constructing the Transaction scope we use the SessionBuilder and ask it to supply an Isolation Level for the role specified. Of course their is some IOC magic involved here but essentially the only thing required to make work is the following interface. Here is an example implementation.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">interface</span> IProvideIsolationLevelFor&lt;TRole&gt;
{
    IsolationLevel GetScopeIsolationForRole { get;}
}

<span style="color: #008000;">///Implementation</span>

<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> RunoutDiscountIsolation :
    IProvideIsolationLevelFor&lt;IRunOutDiscountForProducts&gt;
{
    <span style="color: #0000ff;">public</span> IsolationLevel GetScopeIsolationForRole
    {
        get { <span style="color: #0000ff;">return</span> IsolationLevel.ReadCommitted; }
    }
}</pre>
</div>
<div>This concrete class is responsible (explicitly) for providing the correct isolation level for the <strong><em>IRunOutDiscountForProducts</em></strong> role.</div>
<h3><span style="text-decoration: underline;">Loaded Up</span></h3>
<div>Before looking at each of the four corners of the quadrant, I quickly want to draw your attention to the fact that Specifications, Fetching Strategies, Isolation Levels (for Transactions), Entities and indeed even their Mappings, can all be resolved from a container at runtime, based on the given role.</div>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">_container.Register(AllTypes
    .Of(<span style="color: #0000ff;">typeof</span>(IFetchingStrategy&lt;&gt;))
    .FromAssembly(assembly)
    .Configure(c =&gt; c.LifeStyle.Singleton).WithService.FirstInterface());

_container.Register(AllTypes
    .Of(<span style="color: #0000ff;">typeof</span>(ISpecification&lt;&gt;))
    .FromAssembly(assembly)
    .Configure(c =&gt; c.LifeStyle.Singleton).WithService.FirstInterface());

_container.Register(AllTypes
    .Of(<span style="color: #0000ff;">typeof</span>(IMappingRole&lt;&gt;))
    .FromAssembly(assembly)
    .Configure(c =&gt; c.LifeStyle.Singleton).WithService.FirstInterface());

_container.Register(AllTypes
    .Of(<span style="color: #0000ff;">typeof</span>(IProvideIsolationLevelFor&lt;&gt;))
    .FromAssembly(assembly)
    .Configure(c =&gt; c.LifeStyle.Singleton).WithService.FirstInterface());

_container.Register(AllTypes
    .Of(<span style="color: #0000ff;">typeof</span>(IEntity))
    .FromAssembly(assembly));</pre>
</div>
<div>This will make the understanding an little easier as we move through the rest of the post.</div>
<h3><span style="text-decoration: underline;">Quadrant Position 1.0 – Fetching Strategies</span></h3>
<p>Fetching strategies encapsulate our expression of requirement with respect to Eager and Lazy Loading. This feature is useful, when one considers that the Entity Framework (and most ORM’s for that matter) do not provide these capabilities with a consistent API experience, nor allow for an out of box experience friendly to a configurable or convention based approach to specifying loading characteristics for a given expression of intent. Wouldn’t it be nice if we could ask the ORM to fetch an Entity using a role, one specific to a command that exists within a given business capability? This functionality does exist with NHibernate but not currently with either version of Entity Framework, but the good news is that it is possible. There are a couple of ways of doing this and I have <a href="http://www.simonsegal.net/index.php?s=Fetching+strategy&amp;sbutt=Go">blogged</a> about it more than once. At this point of the discussion it would be useful to show some code and how to configure a Fetching Strategy. First the interface:</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">interface</span> IFetchingStrategy&lt;TRole&gt; : IQueryConfigurable
{
    IEnumerable&lt;IEagerFetchingIntention&gt; Intentions { get; }
    IEnumerable&lt;<span style="color: #0000ff;">string</span>&gt; Includes { get; }
    <span style="color: #0000ff;">void</span> AddIntentions(IEagerFetchingIntention[] intentions);
    <span style="color: #0000ff;">bool</span> ShouldLazyLoad { get; }
    <span style="color: #0000ff;">bool</span> HasInstructions { get; }
}</pre>
</div>
<p>Next let’s look at an implementation (we will skip the base class for now).</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> CustomerPreferedFetchingStratey :
             FetchingStrategy&lt;IMakeCustomerPrefered&gt;
{
    <span style="color: #0000ff;">public</span> CustomerPreferedFetchingStratey()
        : <span style="color: #0000ff;">base</span>(<span style="color: #0000ff;">false</span>) {

            var orders_intention =
                EagerFetchingIntention
                .CreateInstance&lt;IMakeCustomerPrefered,
                                ICollection&lt;IOrder&gt;&gt;(c =&gt; c.Orders);
            var orderlines_intention =
                EagerFetchingIntention
                .CreateInstance&lt;IOrder,
                                ICollection&lt;IOrderLine&gt;&gt;(o =&gt; o.OrderLines);

            <span style="color: #0000ff;">this</span>.AddIntentions(<span style="color: #0000ff;">new</span> IEagerFetchingIntention[]
            {
                orders_intention,
                orders_intention.And(orderlines_intention)
            });
    }
}</pre>
</div>
<div>Without dwelling on all the moving parts, let’s summarise here by saying that this code has the responsibility of building up the ‘includes’ strings<strong><em> </em></strong>(<strong><em>see ObjectContext&lt;T&gt;.Include()</em></strong>) for eager fetching. No more magic strings applied to the ObjectContext.Include(“magic.more.magic”) method. With a Fetching Strategy we can determine our eager fetching in a strongly type fashion by explicitly specify a role to the Fetching Strategy. In this case above, we are using the <strong><em>IMakeCustomerPrefered</em></strong> role.</div>
<h3><span style="text-decoration: underline;"><span style="text-decoration: underline;"><span style="text-decoration: underline;">Quadrant </span>Position</span> 2.0 – Specification</span></h3>
<p>The <a href="http://en.wikipedia.org/wiki/Specification_pattern">Specification pattern</a> evolved around the problem of testing that the state condition of an object is met according to a given specification. This pattern has taken on some new potential with the help of LINQ. Using LINQ Expressions it’s possible to massage this pattern into something of a predicate store and when we think about developing with roles it becomes potentially more powerful again. Here is a quick look at a Specification and some usage:</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">var spec = <span style="color: #0000ff;">new</span> Specification&lt;IRunOutDiscountForProducts&gt;
              (p =&gt; p.UnitPrice &lt; 20M &amp;&amp; p.Supplier.Region == “London”);</pre>
</div>
<p>Pretty simple, the constructor takes the Expression to initialise the boolean test for the specified state. The classical purpose of the pattern is to provide a single function, commonly named “IsSatisfied” to carry out the test against a given object to see if it’s state indeed meets that that has been specified.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">var productToTest = <span style="color: #0000ff;">new</span> Product(){Supplier = <span style="color: #0000ff;">new</span> Supplier()};
var satisfied = spec.IsSatisfiedBy(productToTest);</pre>
</div>
<p>This will code will obviously fail the specification test and IsSatisfiedBy() will return false. Whilst very useful in and of itself, the LINQ Expression enabled version / implementation of this pattern has some features that can be harnessed to apply a level of dynamism to the resolution of query predicates. Let’s have a closer look:</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">interface</span> ISpecification&lt;T&gt; : IQueryConfigurable
{
    Expression&lt;Func&lt;T, <span style="color: #0000ff;">bool</span>&gt;&gt; EvalPredicate { get; }
    Func&lt;T, <span style="color: #0000ff;">bool</span>&gt; EvalFunc { get; }
    <span style="color: #0000ff;">bool</span> IsSatisfiedBy(T entity);
}</pre>
</div>
<p>The interface details the contract to provide both the Expression and Func that will provide the computation required to discern whether a specification has been satisfied. Further to that, these new properties give us opportunities to plug predicates or lambdas into the machinery as well. Looking a little deeper under the covers of the proof of concept code we will find this in operation:</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff;">return</span> _ctx
       .CreateObjectSet&lt;TRole&gt;()
       .Where(predicate.EvalPredicate)
       .ToList();</pre>
</div>
<p>Through operator overloading, Specifications can also be combined for OR and AND conditions:</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">Specification&lt;Customer&gt; german_customer_spec =
    <span style="color: #0000ff;">new</span> Specification&lt;Customer&gt;(c =&gt; c.Country == “Germany”);

Specification&lt;Customer&gt; us_customer_spec =
    <span style="color: #0000ff;">new</span> Specification&lt;Customer&gt;(c =&gt; c.Country == “Usa”);

var comb_country_spec = (german_customer_spec | us_customer_spec);</pre>
</div>
<p>In the case where query predicates help to form a semi static business rule at the query level through filtering, it becomes a reasonably trivial task to deploy a new version or entirely new Specification for any given role, simply by deploying the library.</p>
<h3><span style="text-decoration: underline;"><span style="text-decoration: underline;"><span style="text-decoration: underline;">Quadrant </span>Position</span> 3.0 – Mapping</span></h3>
<p>Now to the latest part of the puzzle to be rolled into the Proof of concept, mapping. Entity Framework 4.0 (sometime after initial release) will be augmented by code only mapping (hallelujah). When one looks at the (current CTP) API for this functionality it becomes immediately evident that this too is something that can be very easily made deterministic by adding a layer of indirection to accommodate this role based approach. The out of the box mapping in EF 4.0 makes working in this manner quite simple given the possibilities provided by the EntityConfiguration&lt;T&gt; class. Here is a simple example:</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> CustomerMapping : EntityConfiguration&lt;ICustomer&gt;
{
    <span style="color: #0000ff;">public</span> CustomerMapping()
    {
        Property(c =&gt; c.CustomerId).IsIdentity();
        Property(c =&gt; c.FirstName).HasMaxLength(50).IsRequired();
        Property(c =&gt; c.LastName).HasMaxLength(50).IsRequired();
        Relationship(c =&gt; c.Orders).IsOptional();
        Relationship(c =&gt; c.Orders).FromProperty(o =&gt; o.Customer);
    }
}</pre>
</div>
<p>What’s required is to take this out of the box solution and add a layer of indirection requiring only a few new actors, an IMapping, an IMappingRole&lt;T&gt;  and a Mapping&lt;T&gt;.</p>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/mappingrolesconcept.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="mappingRolesConcept" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/mappingrolesconcept-thumb.png" border="0" alt="mappingRolesConcept" width="397" height="365" /></a></p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">interface</span> IMapping
{
    Type EntityType { get; }
    <span style="color: #0000ff;">string</span> ObjectSetName { get; }
    StructuralTypeConfiguration Configuration { get; }
}

<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">interface</span> IMappingRole&lt;TRole&gt;
{
    IMapping[] Mappings { get; }
}

<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">abstract</span> <span style="color: #0000ff;">class</span> Mapping&lt;TEntity&gt; :
                      EntityConfiguration&lt;TEntity&gt;, IMapping
{
    <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">string</span> _objectSetName;

    <span style="color: #0000ff;">public</span> Type EntityType
    {
        get { <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">typeof</span>(TEntity); }
    }

    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span> ObjectSetName
    {
        get { <span style="color: #0000ff;">return</span> _objectSetName; }
    }

    <span style="color: #0000ff;">public</span> Mapping(<span style="color: #0000ff;">string</span> objectSetName)
    {
        _objectSetName = objectSetName;
    }

    <span style="color: #0000ff;">public</span> StructuralTypeConfiguration Configuration
    {
        get { <span style="color: #0000ff;">return</span> (StructuralTypeConfiguration)<span style="color: #0000ff;">this</span>; }
    }
}</pre>
</div>
<p>The aggregation of IMapping’s in the Mapping Role will accommodate mapping an aggregate root with reference and collection entities. Here’s a more complete look that includes some implementing Mapping classes.</p>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/mappingrolesclassdiag.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="mappingRolesClassDiag" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/mappingrolesclassdiag-thumb.png" border="0" alt="mappingRolesClassDiag" width="496" height="517" /></a></p>
<p>Below is an example Mapping class, notice that we still need to use the actual Entity Type and not an interface. This is due to EntityConfiguration&lt;T&gt; lacking in support for interfaces (as of today, perhaps that will change or already has with RC 1).</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> ProductMapping : Mapping&lt;Product&gt;
{
    <span style="color: #0000ff;">public</span> ProductMapping(<span style="color: #0000ff;">string</span> objectSetName) : <span style="color: #0000ff;">base</span>(objectSetName)
    {
        Property(p =&gt; p.ProductID).IsIdentity();
        Property(p =&gt; p.ProductName).HasMaxLength(50).IsRequired();
        Property(p =&gt; p.UnitPrice).Precision = 19;
        Property(p =&gt; p.UnitPrice).Scale = 4;
        Relationship(p =&gt; p.Supplier).IsOptional();
        Relationship(p =&gt; p.Supplier).IsOptional().FromProperty(s =&gt; s.Products);
    }
}</pre>
</div>
<h3></h3>
<h3></h3>
<h3><span style="text-decoration: underline;"><span style="text-decoration: underline;"><span style="text-decoration: underline;">Quadrant </span>Position</span> 4.0 – The Repository</span></h3>
<p>The final square on the grid is the Repository. The repository offers nothing more than five overrides of the one method, Get&lt;T&gt;. The five versions of the method are to cover the variable requirements that might crop up when consumers wish to provide Fetching Strategies, Specifications and Entities (concrete ones) inline and directly to the infrastructure. Fetching Strategies are probably the least likely candidate for this requirement but it may come in useful, Specifications on the other hand will from time to time no doubt be populated dynamically from user input, served as part of a request or message and subsequently used as a filter parameter. Let’s have a brief look at the Interface:</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">interface</span> IRepository : IUnitOfWork
{
    IList&lt;TRole&gt; Get&lt;TRole&gt;();
    IList&lt;TRole&gt; Get&lt;TRole&gt;(IQueryConfigurable[] configurables);
    IList&lt;TRole&gt; Get&lt;TRole&gt;(ISpecification&lt;TRole&gt; predicateWhere)
                            <span style="color: #0000ff;">where</span> TRole : <span style="color: #0000ff;">class</span>;
    IList&lt;TRole&gt; Get&lt;TRole&gt;(IFetchingStrategy&lt;TRole&gt; strategy)
                            <span style="color: #0000ff;">where</span> TRole : <span style="color: #0000ff;">class</span>;
    IList&lt;TRole&gt; Get&lt;TRole&gt;(ISpecification&lt;TRole&gt; predicateWhere,
                            IFetchingStrategy&lt;TRole&gt; strategy)
                            <span style="color: #0000ff;">where</span> TRole : <span style="color: #0000ff;">class</span>;
    IoC IocContainer { set; }
    ObjectContext Session { set; }
}</pre>
</div>
<p>The first two versions of Get&lt;T&gt; will resolve as much as they can from the container, a Fetching Strategy, a Specification, the Mapping and will use the closest adjacent Entity type, all based on the identity of the generic parameter – that is, the ROLE. The last three versions of the Get&lt;T&gt; function is provided to work with the Entity Framework in a more familiar mode where and EDMX file can be specified, the concrete Entity Type itself is provided as the role parameter, we can also push through Fetching Strategies and Specifications ‘in-line’ in these scenarios. Probably not my preferred method but it’s available.</p>
<h2><span style="text-decoration: underline;">Configuration</span></h2>
<p>I decided at the death to implement a fluent configuration to prime the infrastructure and create a Repository. The fluent interface is designed with the view to keeping things compact and easy to setup.</p>
<h4><span style="text-decoration: underline;">Resolve it all</span></h4>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> resolves_everything_from_container()
{
    var compParams = <span style="color: #0000ff;">new</span> Dictionary&lt;<span style="color: #0000ff;">string</span>, <span style="color: #0000ff;">string</span>&gt;();
    compParams.Add(_conParamName, _connectionStringOnly);

    var repo = FetchSpec.Configure
                        .With(<span style="color: #0000ff;">new</span> StubIoc()
                            { ScannedAssemblyPath = _scannedAssemblyPath })
                        .AndBuildSession&lt;IRunOutDiscountForProducts&gt;(compParams)
                        .ForRepository();

    var products = repo.Get&lt;IRunOutDiscountForProducts&gt;();
}</pre>
<p>In this example above, we are using a stub for IoC, and hard wiring the scanned assembly path to find all the implementing Fetching Strategies, Specifications, Mappings etc. The default behaviour in the spiking code is to enumerate the assemblies with the executing processes deployment.</p>
<h3><span style="text-decoration: underline;">Provide it all</span></h3>
<p>For those that like the EDMX way of doing things and want to provide all the Fetching and Speciation instructions in line, this is the way to go about it:</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> CustomerBuyingStatusRepository : Repository
{
    <span style="color: #0000ff;">public</span> CustomerBuyingStatusRepository()
    {
        <span style="color: #008000;">//BEWARE THIS STRING WONT COMPILE ITS MESSED UP</span>
        <span style="color: #008000;">//FOR THE PURPOSE OF VIEWING IN THE BROWSER.</span>
        <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">string</span> constring = <span style="color: #006080;">&#8220;metadata=res://*/Northwind.csdl|res://*/&#8221;</span> +
                                 <span style="color: #006080;">&#8220;Northwind.ssdl|res://*/Northwind.msl;&#8221;</span> +
                                 <span style="color: #006080;">&#8220;provider=System.Data.SqlClient;provider &#8220;</span> +
                                 <span style="color: #006080;">&#8220;etc, etc, etc&#8221;</span>;

        <span style="color: #0000ff;">this</span>.IocContainer = <span style="color: #0000ff;">new</span> IoC();
        <span style="color: #0000ff;">this</span>.Session = <span style="color: #0000ff;">new</span> NorthwindEntities(constring);
    }
}

<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> using_concrete_repository_entity_and_inline_spec_and_fetching()
{
    var customersStartWithA =
        <span style="color: #0000ff;">new</span> Specification&lt;Customer&gt;(c =&gt; c.CompanyName.StartsWith(<span style="color: #006080;">&#8220;A&#8221;</span>));

    var fetch = <span style="color: #0000ff;">new</span> FetchingStrategy&lt;Customer&gt;(<span style="color: #0000ff;">true</span>);

    fetch.AddIntentions(<span style="color: #0000ff;">new</span> IEagerFetchingIntention[]
    {
        EagerFetchingIntention.CreateInstance&lt;Customer,
                                              ICollection&lt;IOrder&gt;&gt;(c =&gt; c.Orders)
    });

    var repo = <span style="color: #0000ff;">new</span> CustomerBuyingStatusRepository();

    var custs = repo.Get&lt;Customer&gt;(customersStartWithA, fetch);

    <span style="color: #0000ff;">foreach</span> (var cust <span style="color: #0000ff;">in</span> custs)
    {
        Console.WriteLine(cust.CompanyName);
        cust.MakePrefered();
    }
}</pre>
</div>
<p>I could have easily left out the ability to support this in-line method, given that the purpose of the spike was to proof the role based approach, having it’s greatest value proposition in being resolved dynamically against the Role. Nonetheless it is possible to mix and match or exclusively do either if you absolutely must. No prizes for guessing which mode I am more partial to, however I will reserve final judgement until it gets a good hit out in the real world, remember this is all the result of a brute force spiking effort.</p>
<h3><span style="text-decoration: underline;">What’s Left?</span></h3>
<p>In part 3.0 we will look at concurrency and throughput through the lens of a service layer. I will also make the code download available in part 3.0.</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=Helping%20Entity%20Framework%20v4.0%20play%20it%26rsquo%3Bs%20%3CROLE%3E%20-%20Part%202.0&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F02%2F17%2Fhelping-entity-framework-v40-play-its-role-part-20%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Helping Entity Framework v4.0 play it&rsquo;s <ROLE> - Part 2.0";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/02/17/helping-entity-framework-v40-play-its-role-part-20/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/02/17/helping-entity-framework-v40-play-its-role-part-20/">Helping Entity Framework v4.0 play it&rsquo;s &lt;ROLE&gt; - Part 2.0</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/02/17/helping-entity-framework-v40-play-its-role-part-20/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Doing .NET Days Announcement</title>
		<link>http://www.simonsegal.net/blog/2010/02/13/doing-net-days-announcement/</link>
		<comments>http://www.simonsegal.net/blog/2010/02/13/doing-net-days-announcement/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 01:46:48 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[doing .Net Days]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/02/13/doing-net-days-announcement/</guid>
		<description><![CDATA[ It’s time to get Doing .NET Days off and running for 2010 and whilst we were originally expecting to be running on the 27th of February it has proven difficult to book the training facility for that date. Therefore I can announce that Saturday the 6th of March is locked in and finalised. Please [...]<p><a href="http://www.simonsegal.net/blog/2010/02/13/doing-net-days-announcement/">Doing .NET Days Announcement</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/20pc-black.png" target="_blank"><img style="border-right-width: 0px; margin: 0px 5px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="20pc_black" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/20pc-black-thumb.png" border="0" alt="20pc_black" width="119" height="94" align="left" /></a> It’s time to get <a href="http://www.simonsegal.net/blog/training/">Doing .NET Days</a> off and running for 2010 and whilst we were originally expecting to be running on the 27th of February it has proven difficult to book the training facility for that date. Therefore I can announce that Saturday the 6th of March is locked in and finalised. Please accept our apologies if your plans have been affected by the change of date. You can visit this <a href="http://www.simonsegal.net/blog/training/">link</a> and register via email. Remember seats are fairly limited so if you wish to attend don’t put it off if you can help it.</p>
<p>The topics covered this time around are ‘Helping the Entity Framework play its &lt;ROLE&gt;’, looking at ways of using behavioural roles defined by interfaces in your system to be explicit and achieve lower latency, greater throughput, more highly testable and maintainable code . The second topic will be a practical look at getting started with NServiceBus, including demonstrations taking in messaging patterns such as Publish / Subscribe and full duplex.</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=Doing%20.NET%20Days%20Announcement&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F02%2F13%2Fdoing-net-days-announcement%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Doing .NET Days Announcement";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/02/13/doing-net-days-announcement/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/02/13/doing-net-days-announcement/">Doing .NET Days Announcement</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/02/13/doing-net-days-announcement/feed/</wfw:commentRss>
		</item>
		<item>
		<title>IronPython and the Entity Framework Part 5.0 &#8211; Concluded</title>
		<link>http://www.simonsegal.net/blog/2010/02/06/ironpython-and-the-entity-framework-part-50-concluded/</link>
		<comments>http://www.simonsegal.net/blog/2010/02/06/ironpython-and-the-entity-framework-part-50-concluded/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 10:34:01 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[Entity Framework]]></category>

		<category><![CDATA[IronPython]]></category>

		<category><![CDATA[IronRuby]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/02/06/ironpython-and-the-entity-framework-part-50-concluded/</guid>
		<description><![CDATA[This is the final part of the series on using IronPython together with the Entity Framework.
Part 1.0
In this first instalment we setup the discussion on what we were trying achieve, how to use the __clrtype__ class in IronPython 2.6 to create PODO’s (Plain Old Dlr Objects) ala POCO, for integration with the Entity Framework. Our [...]<p><a href="http://www.simonsegal.net/blog/2010/02/06/ironpython-and-the-entity-framework-part-50-concluded/">IronPython and the Entity Framework Part 5.0 &ndash; Concluded</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p>This is the final part of the series on using IronPython together with the Entity Framework.</p>
<h3><u><a href="http://www.simonsegal.net/blog/2009/12/31/entity-framework-ironpython-and-podos-can-it-be-done-part-1/">Part 1.0</a></u></h3>
<p>In this first instalment we setup the discussion on what we were trying achieve, how to use the __clrtype__ class in IronPython 2.6 to create PODO’s (<strong><u>P</u></strong>lain <strong><u>O</u></strong>ld <strong><u>D</u></strong>lr <strong><u>O</u></strong>bjects) ala POCO, for integration with the Entity Framework. Our aim is to use the Entity Framework using the Beta 2 of Entity Framework 4.0.</p>
<h3><u><a href="http://www.simonsegal.net/blog/2010/01/07/entity-framework-ironpython-and-podos-can-it-be-done-part-2/">Part 2.0</a></u></h3>
<p>We dig in deep and explore the internals of what’s required to create a PODO (POCO for the DLR). We also build an IronPython ObjectContext and determine how to manage mapping between the Entities and Database. We achieve a successful test run and prove that we can in simple cases get IronPython and Entity Framework to worth together in this fashion. Finally in part 2.0 we take steps to verify lazy loading for an entity graph and we strike our first hurdle, leaving us to look forward to part 3 to see if the problems encountered might be overcome.</p>
<h3><u><a href="http://www.simonsegal.net/blog/2010/01/13/entity-framework-ironpython-and-podos-can-it-be-done-part-3/">Part 3.0</a></u></h3>
<p>We start to examine the issues with scalar / native types and see how proxies fit into the puzzle. We check out eager loading and whilst we do have some success we still face a problem in rounding out the whole story. Finally we prepare to journey into debugging a crash dump file for part 4.</p>
<h3><u><a href="http://www.simonsegal.net/blog/2010/01/14/entity-framework-ironpython-and-podos-can-it-be-done-part-4/">Part 4.0</a></u></h3>
<p>Using Visual Studio 2010 we successfully load up our crash dump file in the hope of jumping over the final hurdle. We discover that the specialized version of IronPython 2.6 does not have publicly available debug symbols but we can manage to see where the active thread was when the fatal crash occurred. </p>
<h2>The State of Play</h2>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/squarepegroundhole.png" target="_blank"><img style="border-right-width: 0px; margin: 0px 5px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="squarepegroundhole" border="0" alt="squarepegroundhole" align="left" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/squarepegroundhole-thumb.png" width="198" height="215" /></a> The current set of problems unfortunately leaves us short in terms of using the Entity Framework from IronPython, however I did previously demonstrate (in two parts <a href="http://www.simonsegal.net/blog/2009/02/08/ironruby-and-the-entity-framework-part-1/">here</a> and <a href="http://www.simonsegal.net/blog/2009/03/11/ironruby-and-the-entity-framework-part-2/">here</a>) how this can be achieved by way of introducing an interop layer with C# addressing the Entity Framework.</p>
<p><a href="http://www.simonsegal.net/blog/2009/12/31/entity-framework-ironpython-and-podos-can-it-be-done-part-1/">Part 1.0</a></p>
<p><a href="http://www.simonsegal.net/blog/2010/01/07/entity-framework-ironpython-and-podos-can-it-be-done-part-2/">Part 2.0</a></p>
<p><a href="http://www.simonsegal.net/blog/2010/01/13/entity-framework-ironpython-and-podos-can-it-be-done-part-3/">Part 3.0</a></p>
</p>
<p><a href="http://www.simonsegal.net/blog/2010/01/14/entity-framework-ironpython-and-podos-can-it-be-done-part-4/">Part 4.0</a></p>
<p>It’s my hope that this post will make the previous posts easier to find given my recent problems with a blog scraping site. Finding the original content has been difficult in light of my successfully having the scraping site in question remove my content.</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=IronPython%20and%20the%20Entity%20Framework%20Part%205.0%20%26ndash%3B%20Concluded&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F02%2F06%2Fironpython-and-the-entity-framework-part-50-concluded%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="IronPython and the Entity Framework Part 5.0 &ndash; Concluded";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/02/06/ironpython-and-the-entity-framework-part-50-concluded/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/02/06/ironpython-and-the-entity-framework-part-50-concluded/">IronPython and the Entity Framework Part 5.0 &ndash; Concluded</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/02/06/ironpython-and-the-entity-framework-part-50-concluded/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ADSD, NServiceBus and Nuclear Armament &#8211; the full story!</title>
		<link>http://www.simonsegal.net/blog/2010/02/04/adsd-nservicebus-and-nuclear-armament-the-full-story/</link>
		<comments>http://www.simonsegal.net/blog/2010/02/04/adsd-nservicebus-and-nuclear-armament-the-full-story/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 10:49:48 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[Courses]]></category>

		<category><![CDATA[Distributed]]></category>

		<category><![CDATA[NServiceBus]]></category>

		<category><![CDATA[SOA]]></category>

		<category><![CDATA[Training]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/02/04/adsd-nservicebus-and-nuclear-armament-the-full-story/</guid>
		<description><![CDATA[After having recently sat through Udi’s 5 day course on Advanced Distributed&#160; Systems Design (ADSD) and after several days of quiet introspection punctuated with some random reconnecting to the web full of it’s opinion and ideas, I found myself ever more at peace with the challenges that lie ahead. During a conversation with Udi whilst [...]<p><a href="http://www.simonsegal.net/blog/2010/02/04/adsd-nservicebus-and-nuclear-armament-the-full-story/">ADSD, NServiceBus and Nuclear Armament &ndash; the full story!</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/nuclear-missile.png" target="_blank"><img style="border-right-width: 0px; margin: 0px 5px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="nuclear_missile" border="0" alt="nuclear_missile" align="left" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/02/nuclear-missile-thumb.png" width="133" height="289" /></a>After having recently sat through Udi’s 5 day <a href="http://www.udidahan.com/training/">course</a> on <strong><u>A</u></strong>dvanced <strong><u>D</u></strong>istributed&#160; <strong><u>S</u></strong>ystems <strong><u>D</u></strong>esign (ADSD) and after several days of quiet introspection punctuated with some random reconnecting to the web full of it’s opinion and ideas, I found myself ever more at peace with the challenges that lie ahead. During a conversation with Udi whilst he was here in Melbourne recently, he recalled a <a href="http://twitter.com/markmario/status/6254304647">twitter comment</a> made by my colleague <a href="http://www.markharris.net.au/">Mark</a> wherein he quoted my flippant remark that having NServiceBus at my disposal could be likened to being armed with nuclear weapons. Perhaps it wasn’t the most elegant analogy but I think it conveys the sentiment, I feel able to leverage and harness a great deal energy and power. This sentiment can also be attributed to the many great ideas that you find yourself being exposed to in the ADSD course</p>
<p>In these times of rampant software development technology proliferation, it would be easy to feel overwhelmed and I know from speaking with colleagues that many do, yet somehow I feel more at peace than ever. Technology stacks, frameworks, buzzwords, paradigm shifts, they are all hurtling towards us at a pace most of us have never known and the inertia alone is staggering.</p>
<p>Many of us need help in separating the stuff from the fluff. As Neo said to the architect, “the question is choice”! Well, is it? What are the choices? Do technology choices alone get your system built? No of course they don’t but many have fallen into the trap of behaving as though they do. Ever caught yourself saying something like “oh if I just use MVVM or ASP.NET MVC, my system will be perfect because of benefits X, Y and Z”? Other developers occasionally ask me, “what technology should I learn next” or “how do I future proof myself”? I think they are somewhat surprised by my answer; my advice is to stay as far away as possible from attempting to build value as a <em><strong>vendor stack expert</strong></em> and focus attention on maturing and refining your design and communication skills. It seems obvious really, after all once you have well developed your design and architectural skills, then you are far better placed to make appropriate technology choices. The ensuing&#160; implementation experience will sort out any technology knowledge gaps that you feel the job’s market is causing you to feel downward pressure from. This doesn’t mean ignore technology all together, by all means pull it apart and analyze it, see how it fits but not in isolation – you need to give it it’s context. This became quite plain to me after having been through the course two years ago.</p>
<p>The DDD / SOA course was a lynch pin for me it was the key that has opened many doors. Without the learning in principles first, no technology will stop you from making a mess of things. Again it’s pretty obvious when you say it but I am sure I am not alone as someone who came to the course with a whole set of assumptions based on layered designs and technology fads as a bag of best practice tools and tricks.</p>
<p>I have now had the privilege of sitting this course three times and it never get’s old. Since I first experienced it two years ago, the content has changed a little and become even more refined. Each time I sit through the course I feel more empowered than the last time, the lessons are learned more deeply and start to become part of my psyche. </p>
<p>Some of my fellow <a href="http://rhysc.blogspot.com/2010/01/udi-dahan-advanced-distributed-systems.html">attendees</a> have posted <a href="http://www.paulbatum.com/2010/01/advanced-distributed-systems-design.html">their thoughts</a> upon having completed the course just recently in Melbourne and I suggest you consider their feedback as well. If you haven’t heard there is now a <a href="http://tech.groups.yahoo.com/group/AdvancedDistributedSystemsDesign/">mailing list</a> dedicated to discussing the courses content and if you are planning on attending in London or the US sometime this year you should definitely check out the mailing list.</p>
<p>I would like to leave you with this; if you have not done this course and you have even the vaguest inkling that you might stand to gain something from learning what what some of the best architects in world know but rarely share in great detail, then do whatever it takes to get yourself a seat when next ADSD rolls into town or find a way of bringing Udi and the course to you. </p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=ADSD%2C%20NServiceBus%20and%20Nuclear%20Armament%20%26ndash%3B%20the%20full%20story%21&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F02%2F04%2Fadsd-nservicebus-and-nuclear-armament-the-full-story%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="ADSD, NServiceBus and Nuclear Armament &ndash; the full story!";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/02/04/adsd-nservicebus-and-nuclear-armament-the-full-story/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/02/04/adsd-nservicebus-and-nuclear-armament-the-full-story/">ADSD, NServiceBus and Nuclear Armament &ndash; the full story!</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/02/04/adsd-nservicebus-and-nuclear-armament-the-full-story/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Why the SOA Guru Web Site SUCKS!</title>
		<link>http://www.simonsegal.net/blog/2010/01/30/why-the-soa-guru-web-site-sucks/</link>
		<comments>http://www.simonsegal.net/blog/2010/01/30/why-the-soa-guru-web-site-sucks/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 08:42:11 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/01/30/why-the-soa-guru-web-site-sucks/</guid>
		<description><![CDATA[It came to my attention recently that a site called SOA Guru have been scraping my blog and knocking off every single post and publishing under the name of their Admin user. What really annoys me is not that they are earning money off my work but more so that they are taking credit for [...]<p><a href="http://www.simonsegal.net/blog/2010/01/30/why-the-soa-guru-web-site-sucks/">Why the SOA Guru Web Site SUCKS!</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p>It came to my attention recently that a site called <a href="www.soaguru.com">SOA Guru</a> have been scraping my blog and knocking off every single post and publishing under the name of their Admin user. What really annoys me is not that they are earning money off my work but more so that they are taking credit for it. If you have a story about this site then please blog it and make sure you report them to Google. I wonder if they will re-blog this post, I hope so.</p>
<p>UPDATE: Their re-post of this post is showing a link back here but it&#8217;s been generated by me to combat the scraping.</p>
<p>UPDATE: After making contact via email I received a response explaining that my material would be removed from their site and that appears to have taken place.</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=Why%20the%20SOA%20Guru%20Web%20Site%20SUCKS%21&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F01%2F30%2Fwhy-the-soa-guru-web-site-sucks%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Why the SOA Guru Web Site SUCKS!";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/01/30/why-the-soa-guru-web-site-sucks/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/01/30/why-the-soa-guru-web-site-sucks/">Why the SOA Guru Web Site SUCKS!</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/01/30/why-the-soa-guru-web-site-sucks/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Finding my way with MongoDB and C# &#8211; Part 1.0</title>
		<link>http://www.simonsegal.net/blog/2010/01/26/finding-my-way-with-mongodb-and-c-part-10/</link>
		<comments>http://www.simonsegal.net/blog/2010/01/26/finding-my-way-with-mongodb-and-c-part-10/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 22:40:13 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[Distributed]]></category>

		<category><![CDATA[NOSQL]]></category>

		<category><![CDATA[POCO]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/01/26/finding-my-way-with-mongodb-and-c-part-10/</guid>
		<description><![CDATA[I’m not about to cut all ties with my relational past and abandon the RDBMS. No, indeed that’s not the appropriate response – well at least not at this stage. So an exploration is what is going to be required to help in clarifying whether MongoDB can find a place in my toolbox.
Watching Michael Dirolf [...]<p><a href="http://www.simonsegal.net/blog/2010/01/26/finding-my-way-with-mongodb-and-c-part-10/">Finding my way with MongoDB and C# &ndash; Part 1.0</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I’m not about to cut all ties with my relational past and abandon the RDBMS. No, indeed that’s not the appropriate response – well at least not at this stage. So an exploration is what is going to be required to help in clarifying whether MongoDB can find a place in my toolbox.</p>
<p>Watching <a href="http://nosql.mypopescu.com/post/288988845/video-michael-dirolf-10gen-introduction-to-mongodb">Michael Dirolf</a> recently sparked my imagination, I began to see a <strong><em>potential</em></strong> abundance of goodness that could be applied in many way – possibly alongside a relational database. The potential for its implementation on the query side in a <a href="http://en.wikipedia.org/wiki/Command-query_separation">CQRS</a> architecture for instance, serving as a store for directly bound <a href="http://www.udidahan.com/2009/12/09/clarified-cqrs/">view model</a> data. MongoDB at first glance offers some nice features that would blend well into an architecture that included serving data from inside the web tier; BSON (binary JSON) may resonate well, it’s unceremonious and lite weight. The future promise of sharding as a product feature also has it’s appeal for obvious reasons. </p>
<h3><u>Figure 1.0 – Potential Architecture</u></h3>
<p>My initial enquiry was grounded in the efficacy of putting MongoDB to work in a distributed <a href="http://en.wikipedia.org/wiki/Publish/subscribe">publish / subscribe</a> architecture where <strong>(N)</strong> subscribing instances of autonomous components in a logical service boundary could effectively update N instances of a dedicated view model database. Each view model perhaps sharing an affinity to a web server allowing scaling out both in tandem. In order to sustain eventual consistency, this architecture employs transactional queues. MongoDB achieves it’s scale efficiencies by ignoring some the properties of an RDBMS that are commonly associated with the difficulties in scaling them. What’s clear is that an architecture that heavily leverages <a href="http://en.wikipedia.org/wiki/Publish/subscribe">publish / subscribe</a>, one way messaging and transactional queues (aimed at providing high availability and scale), will also generally require it’s storage to support transactional behavioural properties. MongoDB advertises it’s replication feature set as part of it’s toolbox, this helps achieve eventual consistency across a shared grid of servers but these two worlds are not about to find a way to play well together. In effect, both seem to be coming to a similar problem with a different solution, with MongoDB addressing scale through it’s built-in auto sharding, focusing more intensely on the database alone. For MongoDB to work in this environment would require the ability to enlist database calls in distributed transactions, something that is not supported by design. It would be possible to add a transactional messaging gateway to solve this problem, however there are other database alternatives that would not require me to take that extra step and additional latency.</p>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image15.png"><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://www.simonsegal.net/blog/wp-content/uploads/2010/01/image-thumb13.png" width="425" height="521" /></a> </p>
<p>This of course in <em><strong>no way invalidates</strong></em> assigning value to looking more deeply at MongoDB (and the like), therefore as I plant sign posts along the road about to be travelled and in light of the friction described above, I will now change track somewhat. My next move forward is to get a better grip of what the developer experience is about (not every problem requires the same solution).</p>
<h3><u>Me as Developer - Starting Out</u></h3>
<p>I started out with a somewhat familiar approach, running the JavaScript based shell you can run ad-hoc queries somewhat akin to query analyzer in the SQL Server world. Once installed and having put the binaries in my path environment variable, running the following commands will start up the server and the shell.</p>
<div>
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   1:</span> c:\users\simon.segal\mongod</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   2:</span> c:\users\simon.segal\mongo</pre>
</p></div>
</div>
<h3><u></u></h3>
<h3><u></u></h3>
<h3><u></u></h3>
<h3><u></u></h3>
<p></p>
<h3><u>Figure 2.0 – Mongo Shell &amp; DB</u></h3>
<p></p>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image16.png" target="_blank"><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://www.simonsegal.net/blog/wp-content/uploads/2010/01/image-thumb14.png" width="260" height="199" /></a></p>
<p>Going from download, to install, to running the shell, inserting and querying for data, is really a relatively quick exercise. With just a dash of reading from the <a href="http://www.mongodb.org/display/DOCS/Developer+Zone">excellent documentation</a> (which also has a friendly readable PDF download utility), you can be writing code in the shell very fast. Code like this doesn’t need a lot of explaining to get going.</p>
<h3><u>Listing 1.0 – Mongo Shell</u></h3>
<p></p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&gt;customer = {firstName: <span style="color: #006080">&quot;Jon&quot;</span>, lastName: <span style="color: #006080">&quot;Doe&quot;</span>, DateJoined: <span style="color: #0000ff">new</span> Date(<span style="color: #006080">&quot;2010/01/30&quot;</span>)};
&gt;db.Customers.save(customer);
&gt;db.Customers.find();
{ <span style="color: #006080">&quot;_id&quot;</span> : ObjectId(<span style="color: #006080">&quot;4b5016e65d3c000000006393&quot;</span>), <span style="color: #006080">&quot;firstName&quot;</span> : <span style="color: #006080">&quot;Jon&quot;</span>, <span style="color: #006080">&quot;lastName&quot;</span>
: <span style="color: #006080">&quot;Doe&quot;</span>, <span style="color: #006080">&quot;DateJoined&quot;</span> : <span style="color: #006080">&quot;Sat Jan 30 2010 00:00:00 GMT+1100 (AUS Eastern Daylight
 Time)&quot;</span> }</pre>
</div>
<div>&#160;</div>
<div>Summarising this code, we create a JSON object in our customer variable, save it to the Customers document collection and create the collection itself in the database with one line of code, then finally query to find all documents in the Customers collection. Doing this from a JavaScript shell is nice but developers all build applications and will therefore preferably be working in their code, whether that’s a Data Access Layer or some kind of a Repository. The answer to this problem is a plethora of language specific drivers that are both created and maintained by <a href="http://www.10gen.com/">10Gen</a> and the community. </div>
<div>&#160;</div>
<h3><u>The Officially Supported Drivers</u></h3>
<ul>
<li>C </li>
<li>C++ </li>
<li>Java </li>
<li>Javascript </li>
<li>Perl </li>
<li>PHP </li>
<li>Python </li>
<li>Ruby </li>
</ul>
<h3><u>The Unofficial Community Supported Drivers</u></h3>
</p>
<ul>
<li>C# </li>
<li>Cold Fusion </li>
<li>Erlang </li>
<li>Factor </li>
<li>Fantom </li>
<li>F# </li>
<li>Go </li>
<li>Groovy </li>
<li>PHP </li>
<li>Powershell </li>
<li>Ruby </li>
</ul>
<h3><u>The C# Driver</u></h3>
<p>You can see that Microsoft technology is fairly well represented in these lists but I want to focus on the C# driver and talk about using MongoDB from C# specifically. Here’s some code using the C# driver to help start getting a feel for the API.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCustomer()
{
    var mongo = <span style="color: #0000ff">new</span> Mongo(<span style="color: #006080">&quot;127.0.0.1&quot;</span>, <span style="color: #006080">&quot;27017&quot;</span>);
    mongo.Connect();
    var db = mongo.getDB(<span style="color: #006080">&quot;HR&quot;</span>);
    var employees = db.GetCollection(<span style="color: #006080">&quot;Employees&quot;</span>);
    var employee = <span style="color: #0000ff">new</span> Document();
    employee[<span style="color: #006080">&quot;FirstName&quot;</span>] = <span style="color: #006080">&quot;Simon&quot;</span>;
    employee[<span style="color: #006080">&quot;LastName&quot;</span>] = <span style="color: #006080">&quot;Segal&quot;</span>;
    employee[<span style="color: #006080">&quot;JoinDate&quot;</span>] = DateTime.Now;
    employees.Insert(employee);
    var cursor = employees.FindAll();
    <span style="color: #0000ff">foreach</span> (var emp <span style="color: #0000ff">in</span> cursor.Documents)
    {
        Console.WriteLine(<span style="color: #0000ff">string</span>.Format(
            <span style="color: #006080">&quot;Customer ID is {0}, first name is {1} and &quot;</span> +
            <span style="color: #006080">&quot;last name is {2}&quot;</span>, emp[<span style="color: #006080">&quot;_id&quot;</span>],
            emp[<span style="color: #006080">&quot;FirstName&quot;</span>], emp[<span style="color: #006080">&quot;LastName&quot;</span>]));
        Console.WriteLine(emp.ToString());
    }
}</pre>
</div>
<p>After running this code in Visual Studio we get the following output which prints a formatted string and the JSON representation as is.</p>
<h3><u>Figure 1.0</u></h3>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image17.png"><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://www.simonsegal.net/blog/wp-content/uploads/2010/01/image-thumb15.png" width="244" height="69" /></a> </p>
</p>
<h3><u>Issues</u></h3>
<p>The first problem with writing code like this is that it’s about as far away from being Domain Driven as I can imagine, there is no concept of an Entity, just a Document. Well it’s a Document Database you say – so why don’t I just stop whining and get on with writing code like that above? Sure transaction script might be great for some scenario’s but when I want to work with a richer domain model I don’t think I should need to change to accommodate the drivers API. Let me be clear, I don’t think there is anything wrong with the API, it’s perfectly fine and in fact I think it’s more than pliable enough for me to use it in other ways that will suit me from time to time. </p>
<p>I alluded earlier in the discussion, to the fact that I originally wanted to proof of concept MongoDB for playing a role as an <strong><em>eventually</em></strong> consistent storage for the Query side of an implementation of <a href="http://en.wikipedia.org/wiki/Command-query_separation">CQRS</a>, where views are being bound directly to view model data (as described <a href="http://www.udidahan.com/2009/12/09/clarified-cqrs/">here</a>) via a RESTFul facade. In part 2.0 I am going to look at how we can build a Context object (think DataContext or ObjectContext) to wrap up the C# driver’s functionality and enable working directly with POCO’s, removing any direct requirement to work from the MongoDB API’s Document class. That’s it for now, let’s see where we end up in Part 2.0.</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=Finding%20my%20way%20with%20MongoDB%20and%20C%23%20%26ndash%3B%20Part%201.0&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F01%2F26%2Ffinding-my-way-with-mongodb-and-c-part-10%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Finding my way with MongoDB and C# &ndash; Part 1.0";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/01/26/finding-my-way-with-mongodb-and-c-part-10/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/01/26/finding-my-way-with-mongodb-and-c-part-10/">Finding my way with MongoDB and C# &ndash; Part 1.0</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/01/26/finding-my-way-with-mongodb-and-c-part-10/feed/</wfw:commentRss>
		</item>
		<item>
		<title>CQRS Presentation by Udi Dahan Recorded in Melbourne</title>
		<link>http://www.simonsegal.net/blog/2010/01/25/cqrs-presentation-by-udi-dahan-recorded-in-melbourne/</link>
		<comments>http://www.simonsegal.net/blog/2010/01/25/cqrs-presentation-by-udi-dahan-recorded-in-melbourne/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 23:57:15 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/01/25/cqrs-presentation-by-udi-dahan-recorded-in-melbourne/</guid>
		<description><![CDATA[On the 19th of January 2010 Udi Dahan presented on Command Query Responsibility Segregation. The Presentation took place in front of the Victorian .NET User Group. The video jumps around a bit early on but it does settle after a few minutes or so. Also the audio is a bit low in volume and may [...]<p><a href="http://www.simonsegal.net/blog/2010/01/25/cqrs-presentation-by-udi-dahan-recorded-in-melbourne/">CQRS Presentation by Udi Dahan Recorded in Melbourne</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p>On the 19th of January 2010 Udi Dahan presented on Command Query Responsibility Segregation. The Presentation took place in front of the <a href="http://www.victoriadotnet.com.au/">Victorian .NET User Group</a>. The video jumps around a bit early on but it does settle after a few minutes or so. Also the audio is a bit low in volume and may need a bit of a boost. Many thanks to <a href="http://www.udidahan.com/">Udi</a> and <a href="http://blogesh.wordpress.com/">Mahesh Krishnan</a> (the User Group Organiser) for making this happen. Watch or download the video <a href="http://www.vimeo.com/8944337">here</a>.</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=CQRS%20Presentation%20by%20Udi%20Dahan%20Recorded%20in%20Melbourne&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F01%2F25%2Fcqrs-presentation-by-udi-dahan-recorded-in-melbourne%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="CQRS Presentation by Udi Dahan Recorded in Melbourne";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/01/25/cqrs-presentation-by-udi-dahan-recorded-in-melbourne/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/01/25/cqrs-presentation-by-udi-dahan-recorded-in-melbourne/">CQRS Presentation by Udi Dahan Recorded in Melbourne</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/01/25/cqrs-presentation-by-udi-dahan-recorded-in-melbourne/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Why would you want to test your Windows Workflows and WF Services?</title>
		<link>http://www.simonsegal.net/blog/2010/01/16/why-would-you-want-to-test-your-windows-workflows-and-wf-services/</link>
		<comments>http://www.simonsegal.net/blog/2010/01/16/why-would-you-want-to-test-your-windows-workflows-and-wf-services/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 03:58:53 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[NServiceBus]]></category>

		<category><![CDATA[WF]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/01/16/why-would-you-want-to-test-your-windows-workflows-and-wf-services/</guid>
		<description><![CDATA[ As a an avid NServiceBus admirer my curiosity about the testability of Workflows in .NET 4.0 led me to ask the question in a group setting recently. One of the responses was “why would you want to test a workflow”? The respondent continued with “surely you would only unit test the components leveraged inside [...]<p><a href="http://www.simonsegal.net/blog/2010/01/16/why-would-you-want-to-test-your-windows-workflows-and-wf-services/">Why would you want to test your Windows Workflows and WF Services?</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image14.png"><img style="border-bottom: 0px; border-left: 0px; margin: 0px 5px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image-thumb12.png" border="0" alt="image" width="236" height="198" align="left" /></a> As a an avid <a href="http://www.nservicebus.com/">NServiceBus</a> admirer my curiosity about the testability of Workflows in .NET 4.0 led me to ask the question in a group setting recently. One of the responses was “why would you want to test a workflow”? The respondent continued with “surely you would only unit test the components leveraged inside a workflow”? I have to disagree with this assertion! I do want to test my workflows because of reasons such as:</p>
<ul>
<li>I’d like to know if a given message types and content cause my workflow to behave exactly as I expect.
<ul>
<li>Did my order submission publish a message to any other endpoints interested in the state of the order submissions outcome?</li>
</ul>
</li>
<li>
<div>If the current state of my workflow is about to be de-hydrated, what are my expectations after handling a given message, were the subsequent expected events raised and or messages sent?</div>
</li>
</ul>
<p align="left">These kinds of concerns when dealing with long running processes in my services really do matter – the business requires such co-ordination to work or fail as described by specification and business workflows inherently contain testable logic - think of your average state machine or consider SLA&#8217;s where a de-hydrated (persisted) workflow has passed an acceptable time boundary, raising events commensurate with that business condition. Sure I need to test my business components too but the story is bigger than that!</p>
<p align="left">NServiceBus <a href="http://www.nservicebus.com/Sagas.aspx">Sagas</a> are probably the closest correlation to a workflow in the WF stack and <a href="http://sourceforge.net/apps/mediawiki/nservicebus/index.php?title=Sagas">Sagas</a> are eminently testable with a baked in testing API designed for the purpose. I guess it’s time to check what WF 4.0 has to offer and see what the story is for myself. More on that a bit later.</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=Why%20would%20you%20want%20to%20test%20your%20Windows%20Workflows%20and%20WF%20Services%3F&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F01%2F16%2Fwhy-would-you-want-to-test-your-windows-workflows-and-wf-services%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Why would you want to test your Windows Workflows and WF Services?";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/01/16/why-would-you-want-to-test-your-windows-workflows-and-wf-services/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/01/16/why-would-you-want-to-test-your-windows-workflows-and-wf-services/">Why would you want to test your Windows Workflows and WF Services?</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/01/16/why-would-you-want-to-test-your-windows-workflows-and-wf-services/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Entity Framework, IronPython and PODO&#8217;s &#8211; Can it be done? - Part 4</title>
		<link>http://www.simonsegal.net/blog/2010/01/14/entity-framework-ironpython-and-podos-can-it-be-done-part-4/</link>
		<comments>http://www.simonsegal.net/blog/2010/01/14/entity-framework-ironpython-and-podos-can-it-be-done-part-4/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 09:58:19 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[Entity Framework]]></category>

		<category><![CDATA[IronPython]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/01/14/entity-framework-ironpython-and-podos-can-it-be-done-part-4/</guid>
		<description><![CDATA[We left off with IPY.exe crashing and leaving us a dump file. The code that forced the crash:

orders = ctx.Orders.Where(&#8220;it.CustomerID &#62; &#8216;C&#8217;&#8220;)
for order in Orders:
    print Order.CustomerID


I speculated that something other than member assignment (made by the Entity Framework) to string types in the underlying CLR type of the Python entity was [...]<p><a href="http://www.simonsegal.net/blog/2010/01/14/entity-framework-ironpython-and-podos-can-it-be-done-part-4/">Entity Framework, IronPython and PODO&rsquo;s &ndash; Can it be done? - Part 4</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p>We left off with IPY.exe crashing and leaving us a dump file. The code that forced the crash:</p>
<div id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:0a0d06ae-5d79-4c0d-a863-0dc28fa5dbde" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #000000;">orders </span><span style="color: #000000;">=</span><span style="color: #000000;"> ctx.Orders.Where(</span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">it.CustomerID &gt; &#8216;C&#8217;</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">)
</span><span style="color: #0000ff;">for</span><span style="color: #000000;"> order </span><span style="color: #0000ff;">in</span><span style="color: #000000;"> Orders:
    </span><span style="color: #0000ff;">print</span><span style="color: #000000;"> Order.CustomerID</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></p>
</div>
<p>I speculated that something other than member assignment (made by the Entity Framework) to string types in the underlying CLR type of the Python entity was failing and you might remember some proof of concept code was demonstrated to show a variety of ways in specifying types to _clrfields and property decorators.</p>
<h3><span style="text-decoration: underline;">The Dump File</span></h3>
<p>So decided to <strong><em>re-watch</em></strong> this timely video presentation by <a href="http://blogs.msdn.com/tess/" target="_blank">Tess Ferrandez</a> and hosted by <a href="http://www.hanselman.com/blog/HanselminutesOn9DebuggingCrashDumpsWithTessFerrandezAndVS2010.aspx" target="_blank">Scott Hanselman</a>, to see if I could get myself up to speed quick enough to debug the crash dump in VS 2010.</p>
<p>Not that it’s relevant to this topic per`se but did find something odd in locating the dump file and thought it’s worth mentioning here: when the system notifies you of a crash that produces a dump file (on Vista 64 in this case), it went through a process of:</p>
<ol>
<li>Prompting with the message that IPY.exe had indeed crashed</li>
<li>Where to find the dump file</li>
</ol>
<p>After noting the path of the dump file and clearing these two dialogs, I went to retrieve the dump file only to find it was not at all where the dialog said it would be. I ran the process again and watch the target folder for the dump file and it appears that when the second dialog is cleared the dump file will be deleted – so make a copy before that happens!</p>
<p>Anyway back to the problem at hand. Once having secured a copy of the crash dump file I loaded into VS.NET 2010 (very slow with downloading the debug symbols for the first time). Eventually this is what I was presented with:</p>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/ip-crash-dump-summary.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Crash Dump file in Visual Studio - click to see full size" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/ip-crash-dump-summary-thumb.png" border="0" alt="Crash Dump file in Visual Studio - click to see full size" width="244" height="82" /></a></p>
<p>The information of most note here is the exception information:</p>
<blockquote><p>“The thread tried to read from or write to a virtual address for which it does not have the appropriate access”</p></blockquote>
<p><em></em></p>
<p>Obviously it’s important to know what was happening on the active thread when debugging for a system that crashed. When prompted to break by visual studio when all the debug symbols have been loaded I received the following message:</p>
<blockquote><p>An unhandled exception of type &#8216;System.ExecutionEngineException&#8217; occurred in Unknown Module.</p></blockquote>
<p>Not very useful so far huh! When I open the parallel call stacks I can see that eight threads were active at the time of the crash and that execution stopped in NT.DLL and in particular on the call listed below.</p>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/ip-crash-para-call-stacks.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ip_crash_para_call_stacks" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/ip-crash-para-call-stacks-thumb.png" border="0" alt="ip_crash_para_call_stacks" width="244" height="113" /></a></p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">ntdll<span style="color: #cc6633;">.dll</span>!_ZwWaitForSingleObject@12()  + 0&#215;15 bytes</pre>
</div>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/ip-crash-call-stack.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ip_crash_call_stack" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/ip-crash-call-stack-thumb.png" border="0" alt="ip_crash_call_stack" width="464" height="651" /></a></p>
<p>I’m certainly not familiar with debugging dump files but here is what I garnered from the video with Tess. As we look through Call Stack (above) in Visual Studio, we can see that DLR, IronPython and Entity Framework <strong><em>4.0</em></strong> functions were called just prior to the failure however it would seem that debug symbols for all three are not currently available on the Symbol Servers from Microsoft. I haven’t yet been able to find them nor been able to locate the source for the special IronPython 2.6 Beta Version for .NET framework 4.0. So we appear to be at impasse, I will continue to see if I can get any deeper into the why and wherefore of the crash and hope to find that one day Plain Old DLR Objects (PODO’s) and Entity Framework can play together in harmony.</p>
<h3><span style="text-decoration: underline;">Conclusion</span></h3>
<p>It this point in time I would certainly say that using Entity Framework with IronPython will require you build a managed wrapper class(es) that roll up what you want from the entity framework. I showed this to some extent previously with IronRuby in these <a href="http://www.simonsegal.net/blog/2009/02/08/ironruby-and-the-entity-framework-part-1/">two</a> <a href="http://www.simonsegal.net/blog/2009/03/11/ironruby-and-the-entity-framework-part-2/">posts</a>. Perhaps with a bit of collaborative work the DLR and ADO.NET teams can do a mind meld and move that bit close to making the DLR languages have a more compelling story in this endeavour, however I suppose the question should be asked, is this kind of interop that they have in mind for the dynamic languages?</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=Entity%20Framework%2C%20IronPython%20and%20PODO%26rsquo%3Bs%20%26ndash%3B%20Can%20it%20be%20done%3F%20-%20Part%204&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F01%2F14%2Fentity-framework-ironpython-and-podos-can-it-be-done-part-4%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Entity Framework, IronPython and PODO&rsquo;s &ndash; Can it be done? - Part 4";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/01/14/entity-framework-ironpython-and-podos-can-it-be-done-part-4/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/01/14/entity-framework-ironpython-and-podos-can-it-be-done-part-4/">Entity Framework, IronPython and PODO&rsquo;s &ndash; Can it be done? - Part 4</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/01/14/entity-framework-ironpython-and-podos-can-it-be-done-part-4/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Entity Framework, IronPython and PODO&#8217;s &#8211; Can it be done? - Part 3</title>
		<link>http://www.simonsegal.net/blog/2010/01/13/entity-framework-ironpython-and-podos-can-it-be-done-part-3/</link>
		<comments>http://www.simonsegal.net/blog/2010/01/13/entity-framework-ironpython-and-podos-can-it-be-done-part-3/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 23:17:33 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[Entity Framework]]></category>

		<category><![CDATA[IronPython]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/01/13/entity-framework-ironpython-and-podos-can-it-be-done-part-3/</guid>
		<description><![CDATA[Before we dive into proxies when using POCO in the Entity Framework lets have a quick recap on where we left off in part 2.0.

Entity Framework will load PODO’s (plain old DLR Objects) fine as long as:

No primitives other than strings are used for fields and properties


Eager Loading works when ObjectQuery[T].Include() is used.

TSQL profiling confirms [...]<p><a href="http://www.simonsegal.net/blog/2010/01/13/entity-framework-ironpython-and-podos-can-it-be-done-part-3/">Entity Framework, IronPython and PODO&rsquo;s &ndash; Can it be done? - Part 3</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Before we dive into proxies when using POCO in the Entity Framework lets have a quick recap on where we left off in part 2.0.</p>
<ul>
<li>Entity Framework will load PODO’s (plain old DLR Objects) fine as long as:
<ul>
<li>No primitives other than strings are used for fields and properties</li>
</ul>
</li>
<li>Eager Loading works when ObjectQuery[T].Include() is used.
<ul>
<li>TSQL profiling confirms this.</li>
</ul>
</li>
<li>Lazy Loading does not appear to work at all</li>
<li>Type names of materialized entities are not what are expected for runtime generated proxies.</li>
</ul>
<p>Let’s talk about proxies a little. I wont delve too deep only enough that’s relevant to the problem at hand. Entity Framework creates proxies at runtime for our POCO entities, essentially so the framework can know the entities a vice versa, they maintain the glue so to speak. The glue is there to enable lazy loading and change tracking specifically. If you want to know more about proxies I suggest reading this <a href="http://blogs.msdn.com/adonet/archive/2009/12/22/poco-proxies-part-1.aspx" target="_blank">post</a> from the ADO.Net team blog. Figure 1.0 depicts debug data of a materialized proxy Entity in a C# library. Notice the unusual name of the proxy Entity in the watch window in figure 1.0 – the Entity Framework generates proxy types in the System.Data.Entity.DynamicProxies namespace.</p>
<h3><span style="text-decoration: underline;">Figure 1.0</span></h3>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/podos-part3-proxy-vs2010.png" target="_blank"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="podos_part3_proxy_vs2010" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/podos-part3-proxy-vs2010-thumb.png" border="0" alt="podos_part3_proxy_vs2010" width="450" height="374" /></a></p>
<p>At this point, we know we are not seeing proxy type names come back when we ask our PODO for it’s full name and we are not getting any love from Lazy Loading at all. Our materialized Entities are indeed the type as engineered via __clrtype__ and we saw this when querying for the namespace of the Entity from IronPython in part 2.0.</p>
<p>In a nutshell, the Entity Framework is querying the database and materializing our PODO’s, however given the circumstances its reasonable to argue that no proxying is taking place and hence no lazy loading. Let’s put that theory to the test just a little more shall we! When proxies are employed in the Entity Framework there are two basic usages; proxies that support either Lazy Loading only or Change Tracking with Lazy Loading, the latter option requires all mapped properties be declared virtual and be public or protected. In Python class properties, functions and methods are considered to be as good as virtual, so we will just assume for the moment that this clears the way for the Entity Framework to work with our PODO’s as any other normal compliant class that is <strong><em>proxyable</em></strong> (of course there is no such word).</p>
<p>Since we are getting no proxy generation with our PODO’s then we would equally expect change tracking to fail would we not? Note in figure 1.0 that a (C#) proxy when examined has a reference to the Entity Tracker and other Entity Framework plumbing required to manage it, which we would expect to be missing if our theory about what’s happening to our PODO’s is correct. Let’s now put the whole proxy and change tracking question to rest.</p>
<div id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:8da59957-16d4-4371-8ce7-a840915fa418" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #0000ff;">def</span><span style="color: #000000;"> IsProxy(theType):
    ctxType </span><span style="color: #000000;">=</span><span style="color: #000000;"> ObjectContext.GetObjectType(theType.GetType())
    notNull </span><span style="color: #000000;">=</span><span style="color: #000000;"> theType </span><span style="color: #000000;">!=</span><span style="color: #000000;"> None
    isCtxObj </span><span style="color: #000000;">=</span><span style="color: #000000;"> ctxType </span><span style="color: #000000;">!=</span><span style="color: #000000;"> theType.GetType();
    </span><span style="color: #0000ff;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">\tThis entity is a %(podo)s</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;"> \
                </span><span style="color: #000000;">%</span><span style="color: #000000;">{</span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">podo</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">:theType.GetType()}
    </span><span style="color: #0000ff;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">\tIt&#8217;s type in the ObjectContext is %(ctxType)s</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;"> \
                </span><span style="color: #000000;">%</span><span style="color: #000000;">{</span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">ctxType</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">:ctxType}
    </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> notNull </span><span style="color: #0000ff;">and</span><span style="color: #000000;"> isCtxObj

</span><span style="color: #0000ff;">def</span><span style="color: #000000;"> IsChangeTracking(podo):
    state </span><span style="color: #000000;">=</span><span style="color: #000000;"> ctx.ObjectStateManager.GetObjectStateEntry(podo).State
    </span><span style="color: #0000ff;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">\tIt&#8217;s state is: %(state)s</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;"> </span><span style="color: #000000;">%</span><span style="color: #000000;"> {</span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">state</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">:state}
    </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> state </span><span style="color: #000000;">==</span><span style="color: #000000;"> System.Data.EntityState.Modified

ctx.ProxyCreationEnabled  </span><span style="color: #000000;">=</span><span style="color: #000000;"> True

parents </span><span style="color: #000000;">=</span><span style="color: #000000;"> ctx.ParentRecords\
             .Where(</span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">it.ParentID != &#8216;bob&#8217;</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">)\
             .Include(</span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">ChildRecords</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">)

</span><span style="color: #0000ff;">for</span><span style="color: #000000;"> parent </span><span style="color: #0000ff;">in</span><span style="color: #000000;"> parents:
    </span><span style="color: #0000ff;">print</span><span style="color: #000000;"> parent.ParentID
    parent.ParentName </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">change tracking works nonetheless</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">
    isProxy </span><span style="color: #000000;">=</span><span style="color: #000000;"> IsProxy(parent).ToString()
    isChange </span><span style="color: #000000;">=</span><span style="color: #000000;"> IsChangeTracking(parent).ToString()
    </span><span style="color: #0000ff;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">\tIt is %(proxy)s that this PODO is a proxy</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;"> \
                </span><span style="color: #000000;">%</span><span style="color: #000000;">{</span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">proxy</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">:isProxy}
    </span><span style="color: #0000ff;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">\tIt is %(change)s that this PODO supports </span><span style="color: #800000;">&#8220;</span><span style="color: #000000;"> \
                </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">proxy style change tracking</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;"> </span><span style="color: #000000;">%</span><span style="color: #000000;">{</span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">change</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">:isChange}
    </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> parent.ChildRecords </span><span style="color: #000000;">!=</span><span style="color: #000000;"> None:
        </span><span style="color: #0000ff;">for</span><span style="color: #000000;"> child </span><span style="color: #0000ff;">in</span><span style="color: #000000;"> parent.ChildRecords:
            </span><span style="color: #0000ff;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">\t\tChildID is : </span><span style="color: #800000;">&#8220;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> child.ChildID

ctx.SaveChanges()</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></p>
</div>
<p>We have added two methods, one to check if an Entity is a proxy and another to verify if change tracking is working via our proxy. Running this code produces the following TSQL, subsequent changes to the database and debug window output in NetBeans.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff;">exec</span> sp_executesql N<span style="color: #006080;">&#8216;update [dbo].[ParentRecords]
set [ParentName] = @0
where ([ParentID] = @1)
&#8216;</span>,N<span style="color: #006080;">&#8216;@0 nvarchar(50),@1 char(5)&#8217;</span>,@0=N<span style="color: #006080;">&#8216;change tracking&#8217;</span>,@1=<span style="color: #006080;">&#8216;FGHIJ&#8217;</span></pre>
</div>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/podos-part3-change-track-ok.png" target="_blank"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="podos_part3_change_track_ok" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/podos-part3-change-track-ok-thumb.png" border="0" alt="podos_part3_change_track_ok" width="400" height="92" /></a></p>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image12.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image-thumb10.png" border="0" alt="image" width="260" height="131" /></a></p>
<p>An interesting set of results. As suspected we have no proxies with Lazy Loading or Change tracking ability but we do have change tracking nonetheless when we get a diff from the ObjectContext. The call to .SaveChanges() on the ObjectContext is still persisting the change to the database regardless of the absence of the proxy creation.</p>
<p>To summarise, we now have established that loading data into PODO’s works despite producing no proxy. We can eager load only and we still have the rather large problem with natives that are not strings; this still leaves us with the little problem of this ugly message.</p>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image13.png" target="_blank"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image-thumb11.png" border="0" alt="image" width="417" height="219" /></a></p>
<p>One thing that I meant to mention in one of the earlier posts is that clrtype.py does not support the use of iterables and IronPython classes in the @Accepts and @Returns decorators out of the box. Thanks to help given by <a href="http://twitter.com/cendalc">Lukas Cenovsky</a> on the IronPython <a href="http://groups.google.com/group/ironpy/browse_thread/thread/ce53afbeeba5d694?pli=1" target="_blank">mailing list</a> who made the required changes to the <strong><em>validate_clr_types</em></strong> method in <a href="http://ironpython.net/ironpython/documentation/dotnet/dotnet.html#clrtype">clrtype.py</a> to get over this hurdle.</p>
<p>So now it’s time I thought to jump into VS 2010 and see what we can discover by checking out the dump file created by the IPY.exe crash. And that is where part 4.0 of the series will start. Until then.</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=Entity%20Framework%2C%20IronPython%20and%20PODO%26rsquo%3Bs%20%26ndash%3B%20Can%20it%20be%20done%3F%20-%20Part%203&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F01%2F13%2Fentity-framework-ironpython-and-podos-can-it-be-done-part-3%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Entity Framework, IronPython and PODO&rsquo;s &ndash; Can it be done? - Part 3";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/01/13/entity-framework-ironpython-and-podos-can-it-be-done-part-3/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/01/13/entity-framework-ironpython-and-podos-can-it-be-done-part-3/">Entity Framework, IronPython and PODO&rsquo;s &ndash; Can it be done? - Part 3</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/01/13/entity-framework-ironpython-and-podos-can-it-be-done-part-3/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Udi Dahan to present at Victoria DNUG on 19th January &#8211; CQRS</title>
		<link>http://www.simonsegal.net/blog/2010/01/12/udi-dahan-to-present-at-victoria-dnug-on-19th-january-cqrs/</link>
		<comments>http://www.simonsegal.net/blog/2010/01/12/udi-dahan-to-present-at-victoria-dnug-on-19th-january-cqrs/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 15:22:21 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[Training]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/01/12/udi-dahan-to-present-at-victoria-dnug-on-19th-january-cqrs/</guid>
		<description><![CDATA[Udi Dahan (aka the Software Simplist and original author of NServiceBus) will be presenting to the Victoria.Net User Group on the 19th of January in the Melbourne CBD at Innovation@257, Collins St. The evening begins at 5:30 PM with pizza and drinks and presentations begin at 6:00 PM. Visit this link and register with an [...]<p><a href="http://www.simonsegal.net/blog/2010/01/12/udi-dahan-to-present-at-victoria-dnug-on-19th-january-cqrs/">Udi Dahan to present at Victoria DNUG on 19th January &ndash; CQRS</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Udi Dahan (aka the <a href="http://www.udidahan.com/" target="_blank">Software Simplist</a> and original author of <a href="http://www.nservicebus.com/" target="_blank">NServiceBus</a>) will be presenting to the <a href="http://www.victoriadotnet.com.au/vic_index.aspx">Victoria.Net User Group</a> on the 19th of January in the Melbourne CBD at Innovation@257, Collins St. The evening begins at 5:30 PM with pizza and drinks and presentations begin at 6:00 PM. Visit this link and register with an RSVP as detailed:</p>
<p><a title="RSVP" href="http://www.victoriadotnet.com.au/vic-events/vic-technical-events.aspx" target="_blank">REGISTER HERE</a></p>
<p>If you haven’t come across Command Query Responsibility Segregation (CQRS) before, you can catch up and do some background reading on Udi’s blog at the following spots.</p>
<p><a href="http://www.udidahan.com/2008/08/11/command-query-separation-and-soa/" target="_blank">Command Query Separation and SOA</a></p>
<p><a href="http://www.udidahan.com/2009/12/09/clarified-cqrs/" target="_blank">Clarified CQRS</a></p>
<p>Look forward to seeing a big turn out for this rare opportunity to see Udi present here is Australia.</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=Udi%20Dahan%20to%20present%20at%20Victoria%20DNUG%20on%2019th%20January%20%26ndash%3B%20CQRS&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F01%2F12%2Fudi-dahan-to-present-at-victoria-dnug-on-19th-january-cqrs%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Udi Dahan to present at Victoria DNUG on 19th January &ndash; CQRS";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/01/12/udi-dahan-to-present-at-victoria-dnug-on-19th-january-cqrs/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/01/12/udi-dahan-to-present-at-victoria-dnug-on-19th-january-cqrs/">Udi Dahan to present at Victoria DNUG on 19th January &ndash; CQRS</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/01/12/udi-dahan-to-present-at-victoria-dnug-on-19th-january-cqrs/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Entity Framework &#8211; Repositories, Fetching Strategies, Specification and Mapping &#8211; Using NFetchSpec for Role Driven Development. Parts 1 - 4</title>
		<link>http://www.simonsegal.net/blog/2010/01/11/entity-framework-repositories-fetching-strategies-specification-and-mapping-using-nfetchspec-for-role-driven-development-parts-1-4/</link>
		<comments>http://www.simonsegal.net/blog/2010/01/11/entity-framework-repositories-fetching-strategies-specification-and-mapping-using-nfetchspec-for-role-driven-development-parts-1-4/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 22:08:23 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[DDD]]></category>

		<category><![CDATA[Entity Framework]]></category>

		<category><![CDATA[ORM]]></category>

		<category><![CDATA[POCO]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/01/11/entity-framework-repositories-fetching-strategies-specification-and-mapping-using-nfetchspec-for-role-driven-development-parts-1-4/</guid>
		<description><![CDATA[Over the course of the next month or so I will be posting a series on using a set of helper libraries which I refer to as NFetchSpec. I have taken the somewhat unusual course of creating this dedicated post that will act as an index of sorts for this series. Another reason for this [...]<p><a href="http://www.simonsegal.net/blog/2010/01/11/entity-framework-repositories-fetching-strategies-specification-and-mapping-using-nfetchspec-for-role-driven-development-parts-1-4/">Entity Framework &ndash; Repositories, Fetching Strategies, Specification and Mapping &ndash; Using NFetchSpec for Role Driven Development. Parts 1 - 4</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Over the course of the next month or so I will be posting a series on using a set of helper libraries which I refer to as NFetchSpec. I have taken the somewhat unusual course of creating this dedicated post that will act as an index of sorts for this series. Another reason for this aggregated index page is that the title of the series accurately reflects the intent of its content however not so much in a search friendly way and I want to make sure that it can be easily found by people who are interested in using Repositories, Fetching Strategies, Specifications and code only mapping.</p>
<p>NFetchSpec aims to provide a basis for using Repositories, Fetching Strategies, Specifications and Code Only mapping using a Role Driven methodology. Here is some example consumer code of NFetchSpec:</p>
<h3><span style="text-decoration: underline;">Listing 1.0</span></h3>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">var customersStartWithA =
    <span style="color: #0000ff;">new</span> Specification&lt;IMakeCustomerPrefered&gt;
        (c =&gt; c.CompanyName.StartsWith(&#8221;A&#8221;));

var <span style="color: #0000ff;">fetch</span> = <span style="color: #0000ff;">new</span> FetchingStrategy&lt;IMakeCustomerPrefered&gt;(<span style="color: #0000ff;">true</span>);

<span style="color: #0000ff;">fetch</span>.AddIntentions(<span style="color: #0000ff;">new</span> IEagerFetchingIntention[]
{
    EagerFetchingIntention.CreateInstance&lt;IMakeCustomerPrefered,
                                          ICollection&lt;IOrder&gt;&gt;(c =&gt; c.Orders)
});

var repo = <span style="color: #0000ff;">new</span> CustomerBuyingStatusRepository();

var custs =
    repo.<span style="color: #0000ff;">Get</span>&lt;IMakeCustomerPrefered&gt;(customersStartWithA, <span style="color: #0000ff;">fetch</span>);

foreach (var cust <span style="color: #0000ff;">in</span> custs)
{
    cust.MakePrefered();
}</pre>
</div>
<p>As described in <a href="http://www.simonsegal.net/blog/2010/01/04/helping-entity-framework-v40-play-its-role-part-10/" target="_blank">Part 1.0</a>, a role is an interface that describes a business or system event and can flag our  intention; in the case of the code above, the intention is to make the Customer Preferred. Using NFetchSpec, this style of working (using roles) seeps into all aspects of the code. This is certainly not a requirement to use NFetchSpec and I will give some examples to the contrary as we get deeper into the series of posts, but it is the key reason for developing it. In Listing 1.0 we are using NFetchSpec to create a search predicate using a Specification instance, a Fetching Strategy to determine the most appropriate loading for the role and then finally using the Repository to get a Customer to make preferred. The API of NFetchSpec supports writing code like this, where each of the moving parts can be written in line together, however as mentioned in <a href="http://www.simonsegal.net/blog/2010/01/04/helping-entity-framework-v40-play-its-role-part-10/" target="_blank">Part 1.0</a>, one of the benefits of working in this role driven way is that we can use some IoC techniques to discover the correct Specifications and Fetching Strategies based on their implementing a given role, i.e, the interface that is specified to the Repositories .Get&lt;TRole&gt;() method. This is closer to the intended proposed usage:</p>
<h3><span style="text-decoration: underline;">Listing 2.0</span></h3>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">var repo = <span style="color: #0000ff;">new</span> CustomerBuyingStatusRepository();

var custs =
    repo.<span style="color: #0000ff;">Get</span>&lt;IMakeCustomerPrefered&gt;();</pre>
</div>
<p>The Code here in Listing 2.0 will instruct the NFetchSpec infrastructure to find a fetching strategy and Specification for this role when the overloaded version of the .Get&lt;TRole&gt;() method is called. This approach makes for an extremely flexible approach, swapping out the most appropriate component – if I don’t like the fetching strategy for a given role, I can simply replace it, facilitating just in time performance tuning (in the case of fetching) as we observe the system over time.</p>
<p>Here are the links to the posts in the series. You might notice that some of the links are not complete meaning that that post is yet to come. I will update this list as new posts make there way out.</p>
<p><a href="http://www.simonsegal.net/blog/2010/01/04/helping-entity-framework-v40-play-its-role-part-10/" target="_blank">Helping the Entity Framework Play it&#8217;s &lt;Role&gt; Part 1.0</a> (posted)</p>
<p><a href="http://www.simonsegal.net/blog/2010/02/17/helping-entity-framework-v40-play-its-role-part-20/">Helping the Entity Framework Play it&#8217;s &lt;Role&gt; Part 2.0</a> (posted)</p>
<p><a href="http://www.simonsegal.net/blog/2010/02/21/helping-entity-framework-v40-play-its-role-part-30/" target="_blank">Helping the Entity Framework Play it&#8217;s &lt;Role&gt; Part 3.0</a> (posted)</p>
<p><a href="http://#">Helping the Entity Framework Play it&#8217;s &lt;Role&gt; Part 4.0</a> (not yet posted)</p>
<p>All the code will be available on conclusion with the final post. Just one small thing before signing off, I really want to <a href="http://www.simonsegal.net/blog/2010/01/04/helping-entity-framework-v40-play-its-role-part-10/" target="_blank">re-emphasise</a> that it’s a really good idea to <a href="http://www.infoq.com/presentations/Making-Roles-Explicit-Udi-Dahan" target="_blank">watch Udi</a> present the ideas that lead me to attempt accommodating this approach for Entity Framework.</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=Entity%20Framework%20%26ndash%3B%20Repositories%2C%20Fetching%20Strategies%2C%20Specification%20and%20Mapping%20%26ndash%3B%20Using%20NFetchSpec%20for%20Role%20Driven%20Development.%20Parts%201%20-%204&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F01%2F11%2Fentity-framework-repositories-fetching-strategies-specification-and-mapping-using-nfetchspec-for-role-driven-development-parts-1-4%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Entity Framework &ndash; Repositories, Fetching Strategies, Specification and Mapping &ndash; Using NFetchSpec for Role Driven Development. Parts 1 - 4";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/01/11/entity-framework-repositories-fetching-strategies-specification-and-mapping-using-nfetchspec-for-role-driven-development-parts-1-4/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/01/11/entity-framework-repositories-fetching-strategies-specification-and-mapping-using-nfetchspec-for-role-driven-development-parts-1-4/">Entity Framework &ndash; Repositories, Fetching Strategies, Specification and Mapping &ndash; Using NFetchSpec for Role Driven Development. Parts 1 - 4</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/01/11/entity-framework-repositories-fetching-strategies-specification-and-mapping-using-nfetchspec-for-role-driven-development-parts-1-4/feed/</wfw:commentRss>
		</item>
		<item>
		<title>SOA / DDD 5 Day course with Udi Dahan</title>
		<link>http://www.simonsegal.net/blog/2010/01/10/soa-ddd-5-day-course-with-udi-dahan/</link>
		<comments>http://www.simonsegal.net/blog/2010/01/10/soa-ddd-5-day-course-with-udi-dahan/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 23:39:09 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[DDD]]></category>

		<category><![CDATA[SOA]]></category>

		<category><![CDATA[Training]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/01/10/soa-ddd-5-day-course-with-udi-dahan/</guid>
		<description><![CDATA[Only one week until this years course with Udi begins – very exciting. If you were hoping to attend and you missed out on a spot then you might be pleased that one has opened up at the last minute, so jump on it if you want to attend.

    
   [...]<p><a href="http://www.simonsegal.net/blog/2010/01/10/soa-ddd-5-day-course-with-udi-dahan/">SOA / DDD 5 Day course with Udi Dahan</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Only one week until this years course with Udi <a href="http://www.simonsegal.net/blog/guests-on-demand/" target="_blank">begins</a> – very exciting. If you were hoping to attend and you missed out on a spot then you might be pleased that one has opened up at the last minute, so <a href="http://www.udidahan.com/training/" target="_blank">jump on it</a> if you want to attend.</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=SOA%20%2F%20DDD%205%20Day%20course%20with%20Udi%20Dahan&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F01%2F10%2Fsoa-ddd-5-day-course-with-udi-dahan%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="SOA / DDD 5 Day course with Udi Dahan";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/01/10/soa-ddd-5-day-course-with-udi-dahan/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/01/10/soa-ddd-5-day-course-with-udi-dahan/">SOA / DDD 5 Day course with Udi Dahan</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/01/10/soa-ddd-5-day-course-with-udi-dahan/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Isolated but not entirely forgotten - .NET Conferences Down Under.</title>
		<link>http://www.simonsegal.net/blog/2010/01/08/isolated-but-not-entirely-forgotten-net-conferences-down-under/</link>
		<comments>http://www.simonsegal.net/blog/2010/01/08/isolated-but-not-entirely-forgotten-net-conferences-down-under/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 03:57:08 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[Career]]></category>

		<category><![CDATA[Training]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/01/08/isolated-but-not-entirely-forgotten-net-conferences-down-under/</guid>
		<description><![CDATA[One thing that we sorely lack in Australia is quality conferences for software developers. Yes it’s true we have TechEd but I find that many great presenters do not venture down under for this event. We have nothing that comes vaguely close to something like the Norwegian Developer Conference (NDC) which has been a wonderful [...]<p><a href="http://www.simonsegal.net/blog/2010/01/08/isolated-but-not-entirely-forgotten-net-conferences-down-under/">Isolated but not entirely forgotten - .NET Conferences Down Under.</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p>One thing that we sorely lack in Australia is quality conferences for software developers. Yes it’s true we have TechEd but I find that many great presenters do not venture down under for this event. We have nothing that comes vaguely close to something like the Norwegian Developer Conference (NDC) which has been a wonderful event in the most recent past (just check out the videos). And whilst we can sit in the comfort of our own home and watch a plethora of video downloads from such events, the ambience and opportunity to meet likeminded individuals in the flesh is impoverished. One does not quite so much feel a <a href="http://dictionary.reference.com/browse/mensch?db=dictionary" target="_blank">mensch</a> (the Yiddish meaning), sipping ones coffee on ones couch as one would in the company of an audience in some of software&#8217;s great theatres.</p>
<h3><span style="text-decoration: underline;">Conferences that I (think I) would most like to attend include:</span></h3>
<p><a href="http://qconlondon.com/" target="_blank">QCon in London</a></p>
<p><a href="http://www.ndc2010.no/" target="_blank">NDC</a></p>
<p><a href="http://www.devteach.com/" target="_blank">DevTeach</a></p>
<p><a href="http://www.oredev.org/" target="_blank">Oredev</a></p>
<p><a href="http://live.visitmix.com/" target="_blank">MIX</a></p>
<p>Despite our geographical isolation due largely to the tyranny of distance and the ensuing expense, all is not lost. We do from time to time get some <a href="http://www.udidahan.com/training/" target="_blank">top shelf training</a> events <a href="http://www.simonsegal.net/blog/guests-on-demand/" target="_blank">down under</a>. Of course we have our User Group communities but is that adequate gap filler for the (apparent) vibrancy of the European and North American conference circuits; I’m Imagineering a little here because I have not yet experienced it.</p>
<p>What about an Australian Developers Conference – one to rival the quality say of the NDC? Would you come? Australia is a big place and it seems clear that it would not be practical for it to be held in every city, so I guess it would best be hosted in Melbourne or Sydney. How much would an Australian developer be willing to part with to attend, would your company put up the finance to send you?</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=Isolated%20but%20not%20entirely%20forgotten%20-%20.NET%20Conferences%20Down%20Under.&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F01%2F08%2Fisolated-but-not-entirely-forgotten-net-conferences-down-under%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Isolated but not entirely forgotten - .NET Conferences Down Under.";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/01/08/isolated-but-not-entirely-forgotten-net-conferences-down-under/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/01/08/isolated-but-not-entirely-forgotten-net-conferences-down-under/">Isolated but not entirely forgotten - .NET Conferences Down Under.</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/01/08/isolated-but-not-entirely-forgotten-net-conferences-down-under/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Entity Framework, IronPython and PODO&#8217;s &#8211; Can it be done? - Part 2</title>
		<link>http://www.simonsegal.net/blog/2010/01/07/entity-framework-ironpython-and-podos-can-it-be-done-part-2/</link>
		<comments>http://www.simonsegal.net/blog/2010/01/07/entity-framework-ironpython-and-podos-can-it-be-done-part-2/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 01:17:14 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[Entity Framework]]></category>

		<category><![CDATA[IronPython]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/01/07/entity-framework-ironpython-and-podos-can-it-be-done-part-2/</guid>
		<description><![CDATA[Part 1.0 was setting up for the idea and now in part 2.0 we start to flesh out all the moving parts that would be required to work with IronPython and the Entity Framework and furthermore, do so in such a way that is parallel to how we expect to do so in a statically [...]<p><a href="http://www.simonsegal.net/blog/2010/01/07/entity-framework-ironpython-and-podos-can-it-be-done-part-2/">Entity Framework, IronPython and PODO&rsquo;s &ndash; Can it be done? - Part 2</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.simonsegal.net/blog/2009/12/31/entity-framework-ironpython-and-podos-can-it-be-done-part-1/" target="_blank">Part 1.0</a> was setting up for the idea and now in part 2.0 we start to flesh out all the moving parts that would be required to work with IronPython and the Entity Framework and furthermore, do so in such a way that is parallel to how we expect to do so in a statically typed language such as C#. What we are going to aim for is POCO classes, a custom Object Context and Code Only mapping. </p>
<p>Before we move on a small piece of housekeeping. When you see [T] in this post it is the IronPython version of &lt;T&gt; in the C# world. For example these are equivalent:</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">ObjectQuery&lt;T&gt;

<span style="color: #008000">//and</span>

ObjectQuery[T]</pre>
</div>
<p></p>
<h3><u>PODO / POCO Entities</u></h3>
<p>I gave a bit of a sneak peak at this in Part 1.0 but it’s worth repeating here. Using Northwind (of course – it’s law after all) we could start building out our business Entities for Customers and Orders. Let’s start by keeping the members of our entities to a minimum for brevity sake:</p>
<h3><u>Figure 1.0</u></h3>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="simple model" border="0" alt="simple model" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image-thumb2.png" width="417" height="213" /></a>&#160;</p>
<p>Simple enough, a couple of classes with members types that include System.String, System.DateTime and System.Int32, a list of Orders in the Customer Entity and a single entity reference to Customer from the Order Entity. I posted a Customer Entity in part 1.0 but let’s list both Customer and Order here:</p>
<h3><u>Listing 1.0</u></h3>
<p></p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:62913bd5-eb44-43b1-b7dc-2e31f2eb943a" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #0000FF;">import</span><span style="color: #000000;"> clrtype
</span><span style="color: #0000FF;">import</span><span style="color: #000000;"> clr
</span><span style="color: #0000FF;">from</span><span style="color: #000000;"> System </span><span style="color: #0000FF;">import</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">
</span><span style="color: #0000FF;">from</span><span style="color: #000000;"> System.Collections.Generic </span><span style="color: #0000FF;">import</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">
</span><span style="color: #0000FF;">from</span><span style="color: #000000;"> Entities2.Order </span><span style="color: #0000FF;">import</span><span style="color: #000000;"> Order

</span><span style="color: #0000FF;">class</span><span style="color: #000000;"> Customer(object):

    </span><span style="color: #800080;">__metaclass__</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> clrtype.ClrClass
    _clrnamespace </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">EntityFramework.Podo</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">
    _clrfields </span><span style="color: #000000;">=</span><span style="color: #000000;"> {  </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">_customerId</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">:str,
                    </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">_companyName</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">:str,
                    </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">_contactName</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">:str,
                    </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">_orders</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">:clr.GetClrType(ICollection)
                    .MakeGenericType(Order)
                 }

    @property
    @clrtype.accepts()
    @clrtype.returns(clr.GetClrType(str))
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> CustomerID(self):
        </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> self._customerId

    @CustomerID.setter
    @clrtype.accepts(clr.GetClrType(str))
    @clrtype.returns()
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> CustomerID(self, value):
        self._customerId </span><span style="color: #000000;">=</span><span style="color: #000000;"> value

    @property
    @clrtype.accepts()
    @clrtype.returns(str)
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> CompanyName(self):
        </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> self._companyName

    @CompanyName.setter
    @clrtype.accepts(str)
    @clrtype.returns()
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> CompanyName(self, value):
        self._companyName </span><span style="color: #000000;">=</span><span style="color: #000000;"> value

    @property
    @clrtype.accepts()
    @clrtype.returns(str)
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> ContactName(self):
        </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> self._contactName

    @ContactName.setter
    @clrtype.accepts(str)
    @clrtype.returns()
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> ContactName(self, value):
        self._contactName </span><span style="color: #000000;">=</span><span style="color: #000000;"> value

    @property
    @clrtype.accepts()
    @clrtype.returns(clr.GetClrType(ICollection)
    .MakeGenericType(Order))
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> Orders(self):
        </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> self._orders

    @Orders.setter
    @clrtype.accepts(clr.GetClrType(ICollection)
    .MakeGenericType(Order))
    @clrtype.returns()
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> Orders(self, value):
        self._orders </span><span style="color: #000000;">=</span><span style="color: #000000;"> value</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:eaf51d37-7e8b-4338-a593-4643c255c008" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #0000FF;">import</span><span style="color: #000000;"> clrtype
</span><span style="color: #0000FF;">import</span><span style="color: #000000;"> clr
</span><span style="color: #0000FF;">from</span><span style="color: #000000;"> System </span><span style="color: #0000FF;">import</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">
</span><span style="color: #0000FF;">from</span><span style="color: #000000;"> Entities.Customer </span><span style="color: #0000FF;">import</span><span style="color: #000000;"> Customer

</span><span style="color: #0000FF;">class</span><span style="color: #000000;"> Order(object):

    </span><span style="color: #800080;">__metaclass__</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> clrtype.ClrClass
    _clrnamespace </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">EntityFramework.Podo</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">
    _clrfields </span><span style="color: #000000;">=</span><span style="color: #000000;"> {  </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">_customerId</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">:str,
                    </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">_orderId</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">:int,
                    </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">_orderDate</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">:clr.GetClrType(DateTime),
                    </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">_customer</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">:clr.GetClrType(Customer)
                 }

    @property
    @clrtype.accepts()
    @clrtype.returns(int)
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> OrderID(self):
        </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> self._orderId

    @OrderID.setter
    @clrtype.accepts(int)
    @clrtype.returns()
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> OrderID(self, value):
        self._orderId </span><span style="color: #000000;">=</span><span style="color: #000000;"> value

    @property
    @clrtype.accepts()
    @clrtype.returns(clr.GetClrType(DateTime))
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> OrderDate(self):
        </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> self._orderDate

    @OrderDate.setter
    @clrtype.accepts(clr.GetClrType(DateTime))
    @clrtype.returns()
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> OrderDate(self, value):
        self._orderDate </span><span style="color: #000000;">=</span><span style="color: #000000;"> value

    @property
    @clrtype.accepts()
    @clrtype.returns(str)
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> CustomerID(self):
        </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> self._customerId

    @CustomerID.setter
    @clrtype.accepts(str)
    @clrtype.returns()
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> CustomerID(self, value):
        self._customerId </span><span style="color: #000000;">=</span><span style="color: #000000;"> value

    @property
    @clrtype.accepts()
    @clrtype.returns(clr.GetClrType(Customer))
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> Customer(self):
        </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> self._customer

    @Customer.setter
    @clrtype.accepts(clr.GetClrType(Customer))
    @clrtype.returns()
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> Customer(self, value):
        self._customer </span><span style="color: #000000;">=</span><span style="color: #000000;"> value</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p>Notice the <strong><em>OrderDate</em></strong> property is specifying the System.DateTime data type? Let’s assume the above code will just work; if I run this ad-hoc proof of concept code below in Listing 2.0, I don’t encounter any problems and the output certainly seems to suggest that this should hang together ok when we hook our Customer and Order entities up via mapping to the Entity Framework.</p>
<h3><u>Listing 2.0</u></h3>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:c930f73e-0a77-499e-8901-1307cfc9c61c" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #0000FF;">import</span><span style="color: #000000;"> clrtype
</span><span style="color: #0000FF;">import</span><span style="color: #000000;"> clr
</span><span style="color: #0000FF;">from</span><span style="color: #000000;"> System </span><span style="color: #0000FF;">import</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">

</span><span style="color: #0000FF;">class</span><span style="color: #000000;"> ClrNatives(object):

    </span><span style="color: #800080;">__metaclass__</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> clrtype.ClrClass
    _clrfields </span><span style="color: #000000;">=</span><span style="color: #000000;">    {
                        </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">_clrDate</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">:clr.GetClrType(DateTime),
                        </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">_clrInt32</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">:clr.GetClrType(Int32)
                    }

    @property
    @clrtype.accepts()
    @clrtype.returns(clr.GetClrType(Int32))
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> ClrInt32(self):
        </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">got into accessor</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">
        </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> self._clrInt32

    @ClrInt32.setter
    @clrtype.accepts(clr.GetClrType(Int32))
    @clrtype.returns()
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> ClrInt32(self, value):
        </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">got into the mutator</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">
        self._clrInt32 </span><span style="color: #000000;">=</span><span style="color: #000000;"> value

    @property
    @clrtype.accepts()
    @clrtype.returns(clr.GetClrType(DateTime))
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> ClrDate(self):
        </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">got into accessor</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">
        </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> self._clrDate

    @ClrDate.setter
    @clrtype.accepts(clr.GetClrType(DateTime))
    @clrtype.returns()
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> ClrDate(self, value):
        </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">got into the mutator</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">
        self._clrDate </span><span style="color: #000000;">=</span><span style="color: #000000;"> value

c </span><span style="color: #000000;">=</span><span style="color: #000000;"> ClrNatives()

</span><span style="color: #0000FF;">print</span><span style="color: #000000;"> c.ClrDate.GetType()
</span><span style="color: #0000FF;">print</span><span style="color: #000000;"> c.ClrInt32.GetType()

c.ClrInt32 </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">10</span><span style="color: #000000;">
c.ClrDate </span><span style="color: #000000;">=</span><span style="color: #000000;"> DateTime.Now

</span><span style="color: #0000FF;">print</span><span style="color: #000000;"> c.ClrInt32
</span><span style="color: #0000FF;">print</span><span style="color: #000000;"> c.ClrDate</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<h3><u>Figure 2.0</u></h3>
<p>Figure 2.0 below depicts the output from the code in Listing 2.0 and shows that the underlying CLR type is indeed having the correct types created for it’s backing fields and associated properties.</p>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image3.png"><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://www.simonsegal.net/blog/wp-content/uploads/2010/01/image-thumb3.png" width="260" height="201" /></a> </p>
</p>
<p>The next piece of the puzzle that we would require would be the Entity Framework ObjectContext. Based on the recommended C# pattern for POCO implementation, we would do the following:</p>
<h3><u>Listing 3.0</u></h3>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:1469499d-e9ce-4f08-bdaf-6f7d9838c093" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #0000FF;">class</span><span style="color: #000000;"> NorthwindEntities(ObjectContext):

    </span><span style="color: #800080;">__metaclass__</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> clrtype.ClrClass
    _clrnamespace </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">EntityFramework.Podo</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">
    _clrfields </span><span style="color: #000000;">=</span><span style="color: #000000;"> {
                    </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">_customers</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">:clr.GetClrType(IObjectSet)
                        .MakeGenericType((Customer)),
                    </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">_orders</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">:clr.GetClrType(IObjectSet)
                        .MakeGenericType((Order))
                 }

    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> </span><span style="color: #800080;">__init__</span><span style="color: #000000;">(self):</span><span style="color: #0000FF;">pass</span><span style="color: #000000;">

    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> </span><span style="color: #800080;">__init__</span><span style="color: #000000;">(self, connectionString):
        self._customers </span><span style="color: #000000;">=</span><span style="color: #000000;"> self.CreateObjectSet[Customer]()
        self._orders </span><span style="color: #000000;">=</span><span style="color: #000000;"> self.CreateObjectSet[Order]()
        self.ContextOptions.LazyLoadingEnabled </span><span style="color: #000000;">=</span><span style="color: #000000;"> True;

    @property
    @clrtype.accepts()
    @clrtype.returns(clr.GetClrType(IObjectSet)
        .MakeGenericType((Customer)))
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> Customers(self):
        </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> self._customers

    @Customers.setter
    @clrtype.accepts(clr.GetClrType(IObjectSet)
        .MakeGenericType((Customer)))
    @clrtype.returns()
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> Customers(self, value):
        self._customers </span><span style="color: #000000;">=</span><span style="color: #000000;"> value

    @property
    @clrtype.accepts()
    @clrtype.returns(clr.GetClrType(IObjectSet)
        .MakeGenericType((Order)))
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> Orders(self):
        </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> self._orders

    @Orders.setter
    @clrtype.accepts(clr.GetClrType(IObjectSet)
        .MakeGenericType((Order)))
    @clrtype.returns()
    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> Orders(self, value):
        self._orders </span><span style="color: #000000;">=</span><span style="color: #000000;"> value</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p>Creating an ObjectContext in IronPython was straightforward, inherit from ObjectContext and create IObjectSet[T] backing fields and properties for the entities managed by the context. As I said earlier, this specialised IronPython ObjectContext follows the pattern set out for POCO development where a roughly equivalent C# version would be as follows:</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> NorthwindEntities : ObjectContext
{
    <span style="color: #0000ff">private</span> IObjectSet&lt;Customer&gt; _customers;
    <span style="color: #0000ff">private</span> IObjectSet&lt;OrderLine&gt; _orderLines;
    <span style="color: #0000ff">private</span> IObjectSet&lt;Order&gt; _orders;

    <span style="color: #0000ff">public</span> NorthwindEntities()
        : <span style="color: #0000ff">base</span>(<span style="color: #006080">&quot;name=NorthwindEntities&quot;</span>, <span style="color: #006080">&quot;NorthwindEntities&quot;</span>)
    {

    }

    <span style="color: #0000ff">public</span> NorthwindEntities(<span style="color: #0000ff">string</span> connectionString)
        : <span style="color: #0000ff">base</span>(connectionString, <span style="color: #006080">&quot;NorthwindEntities&quot;</span>)
    {
        _customers = CreateObjectSet&lt;Customer&gt;();
        _orders = CreateObjectSet&lt;Order&gt;();
        _orderLines = CreateObjectSet&lt;OrderLine&gt;();
    }

    <span style="color: #0000ff">public</span> IObjectSet&lt;Customer&gt; Customers
    {
        get
        {
            <span style="color: #0000ff">return</span> _customers;
        }
    }

    <span style="color: #0000ff">public</span> IObjectSet&lt;OrderLine&gt; OrderLines
    {
        get
        {
            <span style="color: #0000ff">return</span> _orderLines;
        }
    }

    <span style="color: #0000ff">public</span> IObjectSet&lt;Order&gt; Orders
    {
        get
        {
            <span style="color: #0000ff">return</span> _orders;
        }
    }
}</pre>
</div>
<h3><u></u></h3>
<h3><u></u></h3>
<h3><u></u></h3>
<h3><u>The Mapping Problem</u></h3>
<p></p>
<p>My original goal was to provide all the moving pieces in IronPython code, even the mapping. Entity Framework 4.0 has a code only option with mapping (no XML required) and that made sense – considering there would be no need to bring any managed C# libraries into the mix. Unfortunately however it’s not currently possible to work with <strong><em>Expression[Func[T]]</em></strong> in IronPython and so the code only mapping is just not going to happen for the moment. Hang on you say – what about all the use of Expressions in the Entity Framework itself? Good question. We are not going to use them! The Entity Framework allows the use of Query Builder methods that take strings as arguments, producing <strong><em>ObjectQuery[T]</em></strong> where T is the entity type.</p>
<h3><u>Lets run It!</u></h3>
<p>At this point we have all the constituent pieces required, all that’s left is to see is whether or not it actually works. We start with some simple client code (running in NetBeans Python Edition) to simply load up some Customers:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:a632ff87-16fc-44c7-9d37-39e2e5c798f8" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #000000;">mappingPart </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">metadata=../Northwind.csdl|../Northwind.ssdl|../Northwind.</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">msl;</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">
providerPart </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">provider=System.Data.SqlClient;provider connection </span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">
dbPart1 </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">string=\&#8221;Data Source=BOOMER\\BOOM09;Initial Catalog=Northwind;</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">
dbPart2 </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">Integrated Security=True;MultipleActiveResultSets=True\&#8221;</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">
cn </span><span style="color: #000000;">=</span><span style="color: #000000;"> mappingPart </span><span style="color: #000000;">+</span><span style="color: #000000;"> providerPart </span><span style="color: #000000;">+</span><span style="color: #000000;"> dbPart1 </span><span style="color: #000000;">+</span><span style="color: #000000;">dbPart2

ctx </span><span style="color: #000000;">=</span><span style="color: #000000;"> NorthwindEntities(cn)

custs </span><span style="color: #000000;">=</span><span style="color: #000000;"> ctx.Customers.Where(</span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">it.CustomerID &gt; &#8216;C&#8217;</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">)

</span><span style="color: #0000FF;">for</span><span style="color: #000000;"> cust </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> custs:
    custOutput </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">The Customer ID is %(id)s and Company Name is %(name)s</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">
    custOutTuple </span><span style="color: #000000;">=</span><span style="color: #000000;"> {</span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">id</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">: cust.CustomerID, </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">name</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">: cust.CompanyName}
    </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> custOutput </span><span style="color: #000000;">%</span><span style="color: #000000;"> custOutTuple</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Before we look at the result of running this code its worth noting one thing about this code above, the mapping portion of the connection string is pointing to a location on disk that specifies where to find the Entity Framework Mapping files. Remember that I said that we were unsuccessful in getting the code only mapping working due the issue with Expression Trees and IronPython. Entity Framework 4.0 does allow us produce mapping files with no code generated entities; this can be achieved in a C# or VB.NET library. Simply create your model in the VS designer as usual, make sure that it maps to your POCO’s in terms of structure, then build the project, specifying to export the mapping files rather than embedded them in the assembly.</p>
<h3><u>Figure 3.0</u></h3>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image11.png"><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://www.simonsegal.net/blog/wp-content/uploads/2010/01/image1-thumb.png" width="301" height="291" /></a> </p>
<p>In Visual Studio 2010 click on the .<strong><em>edmx</em></strong> file in Solution Explorer and remove the Custom Tool in the properties window so it becomes blank. Next, make the Copy to Output Director property either ‘Copy Always’ or ‘Copy if Newer’. Navigate to the output directory after running a build and you should see something similar to these three files (names will vary of course). These three files constitute the mapping.</p>
<h3><u>Figure 4.0</u></h3>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image4.png"><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://www.simonsegal.net/blog/wp-content/uploads/2010/01/image4-thumb.png" width="511" height="339" /></a> </p>
<h3><u>Celebrations? Cigars?</u></h3>
<p>So what output if any? Time to light up a cigar in celebration? What does the output window in NetBeans show us (see figure 4.0)?</p>
<h3><u>Figure 5.0</u></h3>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image5.png"><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://www.simonsegal.net/blog/wp-content/uploads/2010/01/image-thumb4.png" width="485" height="282" /></a> </p>
<p>Looks like we have been successful in getting the Entity Framework to speak directly to our IronPython class doesn’t it. Upon a quick check in SQL Profiler I could confirm that indeed the Customers were being loaded by our IronPython ObjectContext.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">SELECT</span>
[Extent1].[CustomerID] <span style="color: #0000ff">AS</span> [CustomerID],
[Extent1].[CompanyName] <span style="color: #0000ff">AS</span> [CompanyName],
[Extent1].[ContactName] <span style="color: #0000ff">AS</span> [ContactName]
<span style="color: #0000ff">FROM</span> [dbo].[Customers] <span style="color: #0000ff">AS</span> [Extent1]
<span style="color: #0000ff">WHERE</span> [Extent1].[CustomerID] &gt; <span style="color: #006080">&#8216;C&#8217;</span></pre>
</div>
<p>So after some fist pumping and jig dancing, I decided I should see how deep it really went. First thing to check for my mind was loading an entity graph deeper than one entity and also doing that with <strong><em>lazy and eager loading</em></strong>.</p>
<h3><u>Lazy Load the Entity Graph</u></h3>
<p>By making a small change to our code that consumes our IronPython ObjectContext class and iterating over the Order collection present in each Customer record, we would hope to see the Lazy Loading kick in? Drum Roll. Great tension in the air as we press F6 (don’t shoot me it’s NetBeans remember)……..</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:132e4036-9e97-4d5c-8c1a-bb22ebbfc738" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #0000FF;">for</span><span style="color: #000000;"> cust </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> custs:
    </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> cust.CustomerID
    </span><span style="color: #0000FF;">for</span><span style="color: #000000;"> order </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> cust.Orders:
        </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> OrderID</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p>And sadly folks it blows up. What happened exactly? Interestingly enough, all the errors I had encountered up till this point when writing the proof of concept code, were related to mapping mistakes between the PODO’s (IronPython Entities) and my <strong><em>.csdl / .msl and .ssdl</em></strong> mapping files and therefore not insurmountable. This error was more than troubling and had me thinking we had struck a real road block that might not be movable. So how did the error manifest itself?</p>
<h3><u>Figure 6.0</u></h3>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image6.png"><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://www.simonsegal.net/blog/wp-content/uploads/2010/01/image-thumb5.png" width="397" height="199" /></a> </p>
<p>Unfortunately something about iterating the Customer Orders collection was blowing IPY.exe up and producing a crash dump file. I’m starting to believe in destiny just about now because just a week ago I happened across <a href="http://www.hanselman.com/blog/" target="_blank">Scott</a> Hanselman’s <a href="http://channel9.msdn.com/posts/Glucose/Hanselminutes-on-9-Debugging-Crash-Dumps-with-Tess-Ferrandez-and-VS2010/" target="_blank">channel 9 interview</a> of <a href="http://blogs.msdn.com/tess/" target="_blank">Tess Ferranadez</a> who was demonstrating the new dump file debugging capabilities of VS 2010. Looks like I’m about to be checking that feature out a little earlier than I originally imagined. </p>
<p>Let’s hold that thought for a moment and revisit the code briefly before we embark on our voyage into dump files! The most obvious three things I saw as worthy for consideration as to the failure were, the iteration of Orders, something about the nature of the Order Entity itself or lazy loading was a goner? I started to examine the differences between the Customer and Order entities to look for differences that might proffer some clues. Immediately it was clear that the Customer entity only had strings for properties, surely that cant be it I thought, but decided to remove it from the list of possibilities immediately nonetheless. So after quickly testing the Order entity on it’s own (as the aggregate root) it became clear that indeed there might be a problem with primitives translating from Entity Framework over to the type declarations made in the IronPython classes. </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:c3bc23db-ef7d-4969-a42f-51517b2d0751" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #000000;">orders </span><span style="color: #000000;">=</span><span style="color: #000000;"> ctx.Orders.Where(</span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">it.CustomerID &gt; &#8216;C&#8217;</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">)
</span><span style="color: #0000FF;">for</span><span style="color: #000000;"> order </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> Orders:
    </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> Order.CustomerID</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Unfortunately where this was successful with Customer (all strings), it was not so with the Order entity which contained integers and Dates amongst them. Incredulous and unconvinced I decided to create a pure ad-hoc table with a mixture of primitives other than strings and this also confirmed my findings. Even when more exotic (tongue in cheek) types like DateTime were removed from the equation and only Int32 and String were present, the problem remained present. </p>
<p>A sanity check was required at this point. I recalled that I had a pre-existing proof of concept to show that specifying CLR types to the <strong><em>_clrfields</em></strong> and <strong><em>decorators</em></strong> were indeed working in other <strong><em>un-persisted</em></strong> entities, furthermore the IronPython class deriving from ObjectContext itself was example of this (see Listing 2.0 and 3.0). So what on earth was this snag? Using Python either <strong><em>int</em></strong> or <strong><em>clr.GetClrType(Int32)</em></strong> had the same negative effect, the Entity Framework didn’t seem to like either of them. This left me scratching a big whole in my head.</p>
<p>In an attempt to be complete, I still wanted to test lazy and eager loading. Let’s begin by moving our attention to a different Entity Model based on two tables where all the fields were typed as strings, that way I thought I could have a go at eager loading using the <em><strong>.Include(“Load.Path”)</strong></em> extension method which takes a string and returns an ObjectQuery[T] (&lt;T&gt; for C#). Here is the new model and query code.</p>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image7.png" target="_blank"><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://www.simonsegal.net/blog/wp-content/uploads/2010/01/image-thumb6.png" width="401" height="194" /></a> </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:c428819e-51c1-455d-90c2-0d67c1de6103" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #000000;">parents </span><span style="color: #000000;">=</span><span style="color: #000000;"> ctx.ParentRecords.Where(</span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">it.ParentID != &#8216;bob&#8217;</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">).Include(</span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">ChildRecords</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">)

</span><span style="color: #0000FF;">for</span><span style="color: #000000;"> parent </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> parents:
    </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> parent.ParentID
    </span><span style="color: #0000FF;">for</span><span style="color: #000000;"> child </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> parent.ChildRecords:
        </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">\t</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> child.ChildID

</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Success! Judging from the output from this query and iteration, eager loading does appear to work as expected:</p>
<h3><u>Figure 7.0</u></h3>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image8.png"><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://www.simonsegal.net/blog/wp-content/uploads/2010/01/image-thumb7.png" width="230" height="119" /></a> </p>
<p>The SQL Profiler confirms that eager loading has in fact worked as expected. I dislike the SQL that Entity Framework produces – but that’s a subject for a very different post, I just suddenly felt the need for a mini rant.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">SELECT</span>
[Project1].[C1] <span style="color: #0000ff">AS</span> [C1],
[Project1].[ParentID] <span style="color: #0000ff">AS</span> [ParentID],
[Project1].[ParentName] <span style="color: #0000ff">AS</span> [ParentName],
[Project1].[C2] <span style="color: #0000ff">AS</span> [C2],
[Project1].[ChildID] <span style="color: #0000ff">AS</span> [ChildID],
[Project1].[ParentID1] <span style="color: #0000ff">AS</span> [ParentID1],
[Project1].[ChildName] <span style="color: #0000ff">AS</span> [ChildName]
<span style="color: #0000ff">FROM</span> ( <span style="color: #0000ff">SELECT</span>
    [Extent1].[ParentID] <span style="color: #0000ff">AS</span> [ParentID],
    [Extent1].[ParentName] <span style="color: #0000ff">AS</span> [ParentName],
    1 <span style="color: #0000ff">AS</span> [C1],
    [Extent2].[ChildID] <span style="color: #0000ff">AS</span> [ChildID],
    [Extent2].[ParentID] <span style="color: #0000ff">AS</span> [ParentID1],
    [Extent2].[ChildName] <span style="color: #0000ff">AS</span> [ChildName],
    <span style="color: #0000ff">CASE</span> <span style="color: #0000ff">WHEN</span> ([Extent2].[ChildID] <span style="color: #0000ff">IS</span> <span style="color: #0000ff">NULL</span>)
        <span style="color: #0000ff">THEN</span> <span style="color: #0000ff">CAST</span>(<span style="color: #0000ff">NULL</span> <span style="color: #0000ff">AS</span> <span style="color: #0000ff">int</span>) <span style="color: #0000ff">ELSE</span> 1 <span style="color: #0000ff">END</span> <span style="color: #0000ff">AS</span> [C2]
    <span style="color: #0000ff">FROM</span>  [dbo].[ParentRecords] <span style="color: #0000ff">AS</span> [Extent1]
    <span style="color: #0000ff">LEFT</span> <span style="color: #0000ff">OUTER</span> <span style="color: #0000ff">JOIN</span> [dbo].[ChildRecords] <span style="color: #0000ff">AS</span> [Extent2]
        <span style="color: #0000ff">ON</span> [Extent1].[ParentID] = [Extent2].[ParentID]
    <span style="color: #0000ff">WHERE</span> [Extent1].[ParentID] &lt;&gt; <span style="color: #006080">&#8216;bob&#8217;</span>
)  <span style="color: #0000ff">AS</span> [Project1]
<span style="color: #0000ff">ORDER</span> <span style="color: #0000ff">BY</span> [Project1].[ParentID] <span style="color: #0000ff">ASC</span>, [Project1].[C2] ASC</pre>
</div>
<p>How about Lazy Loading? Remember we set the Lazy Loading property of the ObjectContext options in the __init__ (see <strong><em>Listing 3.0</em></strong> above). So let’s check and leave out the .Include() this time:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:7431a8d0-34e9-4df3-b249-dca5479bcc47" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #000000;">parents </span><span style="color: #000000;">=</span><span style="color: #000000;"> ctx.ParentRecords.Where(</span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">it.ParentID != &#8216;bob&#8217;</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">)

</span><span style="color: #0000FF;">for</span><span style="color: #000000;"> parent </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> parents:
    </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> parent.GetType().FullName
    </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> parent.ParentID
    </span><span style="color: #0000FF;">for</span><span style="color: #000000;"> child </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> parent.ChildRecords:
        </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">\t</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> child.ChildID</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>BOOM…no joy here! Let’s have a look at the output and see what went wrong this time.</p>
<h3><u>Figure 8.0</u></h3>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image9.png"><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://www.simonsegal.net/blog/wp-content/uploads/2010/01/image-thumb8.png" width="425" height="132" /></a> </p>
<p>We can see here that we are able to retrieve our ParentRecords without any problem however when ask for the ChildRecords for each Parent then we get a NoneType error, but we know for a fact that record <strong><em>ABCDE</em></strong> indeed has children as exhibited by our eager loading example. I feel myself about to descend down yet another rabbit hole. Lets make a quick check and see if a null check gets us past this point.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:d5982262-966e-42de-a7a6-4e217b45d093" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #0000FF;">for</span><span style="color: #000000;"> parent </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> parents:
    </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> parent.GetType().FullName
    </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> parent.ParentID
    </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> parent.ChildRecords </span><span style="color: #000000;">!=</span><span style="color: #000000;"> None:
        </span><span style="color: #0000FF;">for</span><span style="color: #000000;"> child </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> parent.ChildRecords:
            </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">\t</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> child.ChildID</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Ok, so no error this time but still no lazy load, but at least are we getting closer to knowing the theory around the primitives is accurate?</p>
</p>
<p>How about the mapping what part is that playing in this primitives issue? I added an extra column to the ChildRecord table and use int as it’s data type. Let’s give the ChildRecord Entity an Int64 member whilst the mapping files retain the Int32 mapping. We would expect a mapping error to be reported right? As you can see below that’s exactly what we get. </p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:1f8a2275-60cb-4454-a29f-9e88ac85c8cc" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #000000;">Traceback (most recent call last):

  File </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">C:\Users\simon.segal\Documents\NetBeansProjects\IronPythonEntityFramework\src\main.py</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">, line </span><span style="color: #000000;">33</span><span style="color: #000000;">, </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> C:\Users\simon.segal\Documents\NetBeansProjects\IronPythonEntityFramework\src\main.py

  File </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;">C:\Users\simon.segal\Documents\NetBeansProjects\IronPythonEntityFramework\src\Context.py</span><span style="color: #800000;">&#8220;</span><span style="color: #000000;">, line </span><span style="color: #000000;">36</span><span style="color: #000000;">, </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> </span><span style="color: #800080;">__init__</span><span style="color: #000000;">

SystemError: The type </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">Edm.Int32</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;"> of the member </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">ChildAgeInYears</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;"> </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> the conceptual side type </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">NorthwindModel.ChildRecord</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;"> does </span><span style="color: #0000FF;">not</span><span style="color: #000000;"> match with the type </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">System.Int64</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;"> of the member </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">ChildAgeInYears</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;"> on the object side type </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">EntityFramework.Podo.ChildRecord</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">.</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p>I also made a point of including some code to get a look at the Types full name and we can see that it’s the fully qualified name of the underlying CLR type as specified – that’s good you say, exactly what we want __clrtype__ to do for us. The problem with that is that the Entity Framework 4.0 dials up proxies at runtime when we use POCO, if you debug C# code you can see that asking for the POCO entities fully qualified name returns the proxy details as shown in Figure&#160; 9.0. This is not the case however for our IronPython Entities (see figure 8.0), regardless of our implementing __clrtype__.</p>
<h3><u>Figure 9.0</u></h3>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/image10.png" target="_blank"><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://www.simonsegal.net/blog/wp-content/uploads/2010/01/image-thumb9.png" width="490" height="354" /></a> </p>
<p>In Part 3.0 we will dig into proxies and what they offer, how to setup to use them for different requirements and what effect it may or may not be having on our attempts to get POCO (or rather PODO) lazy loading and change tracking entities working with Entity Framework version 4.0.</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=Entity%20Framework%2C%20IronPython%20and%20PODO%26rsquo%3Bs%20%26ndash%3B%20Can%20it%20be%20done%3F%20-%20Part%202&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F01%2F07%2Fentity-framework-ironpython-and-podos-can-it-be-done-part-2%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Entity Framework, IronPython and PODO&rsquo;s &ndash; Can it be done? - Part 2";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/01/07/entity-framework-ironpython-and-podos-can-it-be-done-part-2/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/01/07/entity-framework-ironpython-and-podos-can-it-be-done-part-2/">Entity Framework, IronPython and PODO&rsquo;s &ndash; Can it be done? - Part 2</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/01/07/entity-framework-ironpython-and-podos-can-it-be-done-part-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Patterns that cross borders - C# to IronPython</title>
		<link>http://www.simonsegal.net/blog/2010/01/06/patterns-that-cross-borders-c-to-ironpython/</link>
		<comments>http://www.simonsegal.net/blog/2010/01/06/patterns-that-cross-borders-c-to-ironpython/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 12:51:36 +0000</pubDate>
		<dc:creator>Simon Segal</dc:creator>
		
		<category><![CDATA[DLR]]></category>

		<category><![CDATA[IronPython]]></category>

		<category><![CDATA[IronRuby]]></category>

		<guid isPermaLink="false">http://www.simonsegal.net/blog/2010/01/06/patterns-that-cross-borders-c-to-ironpython/</guid>
		<description><![CDATA[Recent consideration of the Template Method Pattern got me to wondering about how I might achieve a little more dynamism with respect to declaration, definition and instantiation when using the template method pattern. Without delving too deep into the “classical” Template Method Pattern it can be described here in code with the most trivial of [...]<p><a href="http://www.simonsegal.net/blog/2010/01/06/patterns-that-cross-borders-c-to-ironpython/">Patterns that cross borders - C# to IronPython</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Recent consideration of the Template Method Pattern got me to wondering about how I might achieve a little more dynamism with respect to declaration, definition and instantiation when using the template method pattern. Without delving too deep into the “classical” Template Method Pattern it can be described here in code with the most trivial of examples.</p>
<h3><u>C# Classic Template Method Pattern</u></h3>
<p> 
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">abstract</span> <span style="color: #0000ff">class</span> FootballMatch
{
    <span style="color: #0000ff">abstract</span> <span style="color: #0000ff">void</span> StartGame();

    <span style="color: #0000ff">abstract</span> <span style="color: #0000ff">void</span> EndGame();

    <span style="color: #0000ff">public</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">void</span> PlayGame()
    {
        Console.Writeline(<span style="color: #006080">&quot;Players kick the ball around a field&quot;</span>);
    }

    <span style="color: #0000ff">public</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">void</span> CompleteMatch()
    {
        StartGame();
        PlayGame();
        EndGame();
        Console.WriteLine(<span style="color: #006080">&quot;Match completed thanks for attending!&quot;</span>);
    }
}

<span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> AustralianRulesFootballMatch : FootballMatch
{
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> StartGame()
    {
        Console.WriteLine(<span style="color: #006080">&quot;Siren blows to begin game&#8230;.&quot;</span>);
    }

    <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> EndGame()
    {
        Console.WriteLine(<span style="color: #006080">&quot;Siren blows to end game&#8230;.&quot;</span>);
    }
}

<span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> SoccerFootballMatch : FootballMatch
{
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> StartGame()
    {
        Console.WriteLine(<span style="color: #006080">&quot;Referee blows whistle to begin game&#8230;.&quot;</span>);
    }

    <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> EndGame()
    {
        Console.WriteLine(<span style="color: #006080">&quot;Referee blows whistle to end game&#8230;.&quot;</span>);
    }
}</pre>
</div>
<h3><u></u></h3>
<h3>&#160;</h3>
<h3><u>What about Functions? And how about runtime implementer?</u></h3>
<p>As described above, the implementing classes are defined at design time as concrete derived classes. Doing this in Languages such as Python and Ruby seems a little more flexible in as much that I don’t really require the derivation through an abstract class.</p>
<h3><u>An IronPython Implementation</u></h3>
<p></p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:e3df84ea-cc14-466b-9d84-f699f9ac4980" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #0000FF;">class</span><span style="color: #000000;"> RestuarantEndToEndService:

    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> </span><span style="color: #800080;">__init__</span><span style="color: #000000;">(self, servicename, m1, m2, m3, m4):
        self._serviceName </span><span style="color: #000000;">=</span><span style="color: #000000;"> servicename
        self._greetAndQualifyCustomer </span><span style="color: #000000;">=</span><span style="color: #000000;"> m1
        self._takeCustomerOrder </span><span style="color: #000000;">=</span><span style="color: #000000;"> m2
        self._serveTheCustomerMeal </span><span style="color: #000000;">=</span><span style="color: #000000;"> m3
        self._takePayment </span><span style="color: #000000;">=</span><span style="color: #000000;"> m4

    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> prepareTheMeal(self):
        </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">Chef prepares the meal</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">

    </span><span style="color: #0000FF;">def</span><span style="color: #000000;"> performService(self):
        </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">Doing %(svc)s Service</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;"> </span><span style="color: #000000;">%</span><span style="color: #000000;"> {</span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">svc</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;"> : self._serviceName}
        self._greetAndQualifyCustomer()
        self._takeCustomerOrder()
        self.prepareTheMeal()
        self._serveTheCustomerMeal()
        self._takePayment()

</span><span style="color: #0000FF;">def</span><span style="color: #000000;"> seatCustomer():
    </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">Greet and seat the customer at their table</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">

</span><span style="color: #0000FF;">def</span><span style="color: #000000;"> answerOrdersPhoneLine():
    </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">Answer the phone and take the customer details</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">

</span><span style="color: #0000FF;">def</span><span style="color: #000000;"> takeCustomerOrder():
    </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">Waiter / Waitress takes the customers order</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">

</span><span style="color: #0000FF;">def</span><span style="color: #000000;"> takeCustomerPhoneOrder():
    </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">Take the customers order by phone</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">

</span><span style="color: #0000FF;">def</span><span style="color: #000000;"> serveTheCustomer():
    </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">Waiter / Waitress serves customer their meal</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">

</span><span style="color: #0000FF;">def</span><span style="color: #000000;"> deliverTheCustomerPhoneOrder():
    </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">Driver delivers the customers phone order</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">

</span><span style="color: #0000FF;">def</span><span style="color: #000000;"> takeCustomerPaymentAtCounter():
    </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">Cashier takes customer payment</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">

</span><span style="color: #0000FF;">def</span><span style="color: #000000;"> takeCustomerPaymentOnDelivery():
    </span><span style="color: #0000FF;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">Driver takes customer payment</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">

inhouseService </span><span style="color: #000000;">=</span><span style="color: #000000;"> RestuarantEndToEndService(</span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">In House</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">,
                    seatCustomer,
                    takeCustomerOrder,
                    serveTheCustomer,
                    takeCustomerPaymentAtCounter)
deliveryService </span><span style="color: #000000;">=</span><span style="color: #000000;"> RestuarantEndToEndService(</span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">Delivered</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">,
                    answerOrdersPhoneLine,
                    takeCustomerPhoneOrder,
                    deliverTheCustomerPhoneOrder,
                    takeCustomerPaymentOnDelivery)

inhouseService.performService()
</span><span style="color: #0000FF;">print</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8216;</span><span style="color: #800000;">***********************</span><span style="color: #800000;">&#8216;</span><span style="color: #000000;">
deliveryService.performService()
</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<h3><u>The DLR, Interop and shifting the code around</u></h3>
<p>What’s a little more interesting is using this pattern in interop scenarios when the templated class is defined in a statically typed language and the template method is supplied by a dynamic language created for the DLR. This can be demonstrated here with the given abstract class and by using my IronPython <a href="http://www.simonsegal.net/blog/2009/05/30/a-wpf-ironruby-scripting-console-user-control/" target="_blank">WPF interactive console control</a>.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">abstract</span> <span style="color: #0000ff">class</span> TemplateClass
{
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">abstract</span> <span style="color: #0000ff">void</span> Operation1();
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">abstract</span> <span style="color: #0000ff">void</span> Operation2();

    <span style="color: #008000">/// &lt;summary&gt;</span>
    <span style="color: #008000">/// The Tempate Method</span>
    <span style="color: #008000">/// &lt;/summary&gt;</span>
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> TheTemplateMethod()
    {
        Operation1();
        Operation2();
    }
}</pre>
</div>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/ip-swap-abstract-from-csharp.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ip_swap_abstract_from_csharp" border="0" alt="ip_swap_abstract_from_csharp" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/ip-swap-abstract-from-csharp-thumb.png" width="461" height="377" /></a> </p>
<p>Using the Python <strong><em>Help</em></strong> function we can examine the abstract template class and see how it’s been defined. Looking at the printed help on the class it’s clear that the two abstract methods have ‘<strong><em>tagged along for the ride</em></strong>’ as expected. You wont be able to execute them until you provide an implementation, just as you would expect given it’s an abstract class.</p>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/ip-swap-abstract-from-csharp-help.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ip_swap_abstract_from_csharp_help" border="0" alt="ip_swap_abstract_from_csharp_help" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/ip-swap-abstract-from-csharp-help-thumb.png" width="461" height="542" /></a> </p>
<p>The other scenario involves moving some statically typed code (a method) to the IronPython runtime and using an Action / Delegate to&#160; ‘<strong><em>fill in</em></strong>’ the template algorithm in a dynamically typed class. For example in the <strong><em>EndToEndRestuarantService</em></strong> class defined in Python above, we could push the actions (delegates) over from C# to the IronPython runtime. Given a set of Functions defined in managed C#:</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">var actions = <span style="color: #0000ff">new</span> Dictionary&lt;<span style="color: #0000ff">string</span>, <span style="color: #0000ff">object</span>&gt;();
actions.Add(<span style="color: #006080">&quot;seat&quot;</span>, seat_customer);
actions.Add(<span style="color: #006080">&quot;order&quot;</span>, take_customerOrder);
actions.Add(<span style="color: #006080">&quot;serve&quot;</span>, serve_the_customer);
actions.Add(<span style="color: #006080">&quot;pay&quot;</span>, take_customer_payment_at_counter);</pre>
</div>
<p>When you push these functions over the <a href="http://blogs.msdn.com/seshadripv/archive/2008/08/06/notes-on-scriptscope.aspx" target="_blank">Script Scope</a> running the IronPython code, then you can pass those functions around to any other code running within the same scope. With our Restaurant example we can take our named functions from the C# code at runtime and push them into the constructor of our IronPython class:</p>
<p><a href="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/ip-swap-abstract-from-csharp-func-constructs.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ip_swap_abstract_from_csharp_func_constructs" border="0" alt="ip_swap_abstract_from_csharp_func_constructs" src="http://www.simonsegal.net/blog/wp-content/uploads/2010/01/ip-swap-abstract-from-csharp-func-constructs-thumb.png" width="461" height="680" /></a> </p>
<h3><u>When is this pattern useful?</u></h3>
</p>
</p>
</p>
<p>These patterns can be useful in scenarios where you might be considering scripting your managed C# application and providing DLR supported scripting functionality to the application as well. It can also be quite useful when you want to expose some technology that <a href="http://www.simonsegal.net/blog/2009/04/07/entity-framework-profiler-hosts-ironruby-and-ironpython/" target="_blank">does not currently support full interop</a> (Entity Framework for example) or perhaps you want to make our application model visible to IronPython or IronRuby. There are of course a plethora of patterns that can be implemented in code that can traverse both environments; its really a matter of what we can devise with some imagination.</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=Living%20in%20the%20Tech%20Avalanche%20Generation&amp;siteurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F&amp;linkname=Patterns%20that%20cross%20borders%20-%20C%23%20to%20IronPython&amp;linkurl=http%3A%2F%2Fwww.simonsegal.net%2Fblog%2F2010%2F01%2F06%2Fpatterns-that-cross-borders-c-to-ironpython%2F"><img src="http://www.simonsegal.net/blog/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Patterns that cross borders - C# to IronPython";
		a2a_linkurl="http://www.simonsegal.net/blog/2010/01/06/patterns-that-cross-borders-c-to-ironpython/";
				a2a_show_title=1;    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p><p><a href="http://www.simonsegal.net/blog/2010/01/06/patterns-that-cross-borders-c-to-ironpython/">Patterns that cross borders - C# to IronPython</a> is a post from: <a href="http://www.simonsegal.net/blog">Living in the Tech Avalanche Generation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonsegal.net/blog/2010/01/06/patterns-that-cross-borders-c-to-ironpython/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.376 seconds -->
