<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>statichippo</title>
        <link>http://statichippo.com/blog/Default.aspx</link>
        <description>Noah Blumenthal's journey to become a great developer</description>
        <language>en-US</language>
        <copyright>Noah</copyright>
        <generator>Subtext Version 2.5.2.0</generator>
        <image>
            <title>statichippo</title>
            <url>http://statichippo.com/blog/images/RSS2Image.gif</url>
            <link>http://statichippo.com/blog/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <item>
            <title>Social engineering in the wild</title>
            <link>http://statichippo.com/blog/archive/2012/01/13/social-engineering-in-the-wild.aspx</link>
            <description>&lt;p&gt;My friend just called me to tell me something that happened to him.  He received a phone call from an unknown number.  There was a man on the other line who claimed to be from the internet provider or something of the sort and told my friend that he noticed that my friend’s router and therefore computers had been infected with a virus.  My friend was told to go to one of his internet-connected computers and the caller would step him through the necessary process to rid himself of this virus.  Luckily my friend realized this seemed fishy (or phishy I suppose) and started asking the caller some questions, received no good answers, and decided to hang up.&lt;/p&gt;  &lt;p&gt;Beware!&lt;/p&gt;&lt;img src="http://statichippo.com/blog/aggbug/84.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Noah</dc:creator>
            <guid>http://statichippo.com/blog/archive/2012/01/13/social-engineering-in-the-wild.aspx</guid>
            <pubDate>Fri, 13 Jan 2012 18:57:36 GMT</pubDate>
            <comments>http://statichippo.com/blog/archive/2012/01/13/social-engineering-in-the-wild.aspx#feedback</comments>
            <wfw:commentRss>http://statichippo.com/blog/comments/commentRss/84.aspx</wfw:commentRss>
            <trackback:ping>http://statichippo.com/blog/services/trackbacks/84.aspx</trackback:ping>
        </item>
        <item>
            <title>Dynamic configuration settings in .NET 4</title>
            <category>.NET Framework</category>
            <category>ASP.NET</category>
            <category>c#</category>
            <link>http://statichippo.com/blog/archive/2012/01/12/dynamic-configuration-settings-in-net-4.aspx</link>
            <description>&lt;p&gt;We have a default implementation over our API that we can customize for clients.  In order to support different feature-sets we have a custom configuration section inside our web.config that looks similar to this:&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;&amp;lt;sites&amp;gt;
    &amp;lt;add name="statichippo"&amp;gt;
        &amp;lt;hosts&amp;gt;
            &amp;lt;add name="blog.statichippo.com" /&amp;gt;
        &amp;lt;/hosts&amp;gt;
        &amp;lt;profile enabled="true" /&amp;gt;
    &amp;lt;/add&amp;gt;
...
&amp;lt;/sites&amp;gt;&lt;/pre&gt;

&lt;p&gt;and this works well for the most part.  But we have some clients that have certain one-off features and settings that aren’t part of our main offering and don’t make sense to be added to our custom &lt;em&gt;ConfigurationSection&lt;/em&gt; class.  But it is still important to me to be able to store the associated settings in the same place and I still wanted the settings to be accessible from the same class.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;&amp;lt;sites&amp;gt;
    &amp;lt;add name="statichippo"&amp;gt;&lt;br /&gt;...
        &amp;lt;custom myspaceUrl="whostillusesmyspace?" /&amp;gt;
    &amp;lt;/add&amp;gt;
&amp;lt;/sites&amp;gt;&lt;/pre&gt;

&lt;p&gt;I ended up adding a &lt;em&gt;CustomSettings &lt;/em&gt;property to the &lt;em&gt;SiteElement &lt;/em&gt;that the &amp;lt;sites&amp;gt; elements map to.  It’s type?  &lt;em&gt;dynamic.&lt;/em&gt;  The API is real simple, you just use the same attribute/element name specified in the web.config to access the value, e.g. &lt;em&gt;CustomSettings.myspaceUrl&lt;/em&gt;.  In our case we use AutoMapper to map to a poco class which is useful to prevent runtime issues due to fat fingers on the dynamic type (plus AutoMapper provides a test to ensure you mapped all your properties).  I overrode the &lt;em&gt;OnDeserializeUnrecognizedElement&lt;/em&gt; hook inherited from the parent &lt;em&gt;ConfigurationElement &lt;/em&gt;class to set it.  Here’s the code:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;/// &amp;lt;summary&amp;gt;
/// Custom settings, set via OnDeserializeUnrecognizedElement
/// &amp;lt;/summary&amp;gt;
private dynamic CustomSettings { get; set; }

protected override bool OnDeserializeUnrecognizedElement(string elementName, System.Xml.XmlReader reader)
{
    if (elementName == "custom")
    {
        // create dyamic element to house the settings
        CustomSettings = new DynamicElement(elementName);
        // deserialize settings into dynamic element
        CustomSettings.Deserialize(reader);
        // yes, we've handled the unrecognized element
        return true;
    }
    return base.OnDeserializeUnrecognizedElement(elementName, reader);
}  &lt;/pre&gt;

&lt;p&gt;This basically just alters the hander to deal with a &amp;lt;custom&amp;gt; element by using the &lt;em&gt;DynamicElement&lt;/em&gt;.’s &lt;em&gt;Deserialize&lt;/em&gt; method to read the section.  Here’s the code for &lt;em&gt;DynamicElement&lt;/em&gt;:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;/// &amp;lt;summary&amp;gt;
/// Used to interpret custom settings
/// &amp;lt;/summary&amp;gt;
public class DynamicElement : System.Dynamic.DynamicObject
{
    #region ConfigElement class
    /// &amp;lt;summary&amp;gt;
    /// Used to plug into protected ConfigurationElement methods that need overriding
    /// &amp;lt;/summary&amp;gt;
    private class InnerConfigurationElement : ConfigurationElement
    {
        private DynamicElement _parent;
        internal InnerConfigurationElement(DynamicElement parent)
        {
            _parent = parent;
        }

        protected override bool OnDeserializeUnrecognizedAttribute(string name, string value)
        {
            if (_parent.Attributes.ContainsKey(name))
                return false;

            _parent.Attributes.Add(name, value);
            return true;
        }

        protected override bool OnDeserializeUnrecognizedElement(string elementName, System.Xml.XmlReader reader)
        {
            var element = new DynamicElement(elementName);
            element.Deserialize(reader);
            _parent.ChildElements.Add(element);
            return true;
        }

        internal void Deserialize(System.Xml.XmlReader reader)
        {
            DeserializeElement(reader, serializeCollectionKey: false);
        }
    }
    #endregion

    public string Name { get; private set; }
    internal readonly Dictionary&amp;lt;string, string&amp;gt; Attributes = new Dictionary&amp;lt;string, string&amp;gt;();
    internal readonly List&amp;lt;DynamicElement&amp;gt; ChildElements = new List&amp;lt;DynamicElement&amp;gt;();
    private InnerConfigurationElement _configElement { get; set; }
    internal DynamicElement(string name)
    {
        Name = name;
        _configElement = new InnerConfigurationElement(this);
    }

    public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
    {
        // search attributes first
        if (Attributes.ContainsKey(binder.Name))
        {
            result = Attributes[binder.Name];
            return true;
        }

        // then search child elements
        var childElement = ChildElements.FirstOrDefault(x =&amp;gt; x.Name == binder.Name);
        if (childElement != null)
        {
            result = childElement;
            return true;
        }

        result = null;
        return false;
    }

    public override IEnumerable&amp;lt;string&amp;gt; GetDynamicMemberNames()
    {
        return base.GetDynamicMemberNames();
    }

    public override bool TryConvert(System.Dynamic.ConvertBinder binder, out object result)
    {
        return base.TryConvert(binder, out result);
    }

    public void Deserialize(System.Xml.XmlReader reader)
    {
        _configElement.Deserialize(reader);
    }
}&lt;/pre&gt;

&lt;p&gt;it’s a bit longwinded but it’s actually pretty simple.  The &lt;em&gt;ConfigElement class &lt;/em&gt;region just contains the definition for an &lt;em&gt;InnerConfigurationElement&lt;/em&gt; class.  I didn’t want to have to write any xml parsing code since Microsoft provides that out of the box via the &lt;em&gt;ConfigurationElement&lt;/em&gt; class.  However, since that class’s entry hook, &lt;em&gt;DeserializeElement&lt;/em&gt;, is protected I inherited from it and declared an internal &lt;em&gt;Deserialize&lt;/em&gt; method that just calls into this one.  I also overrode the &lt;em&gt;OnDeserializeUnrecognizedAttribute &lt;/em&gt;and &lt;em&gt;OnDeserializeUnrecognizedElement &lt;/em&gt;methods the latter of which just creates a new &lt;em&gt;DynamicElement&lt;/em&gt; and recursively calls the &lt;em&gt;Deserialize&lt;/em&gt; method on it.&lt;/p&gt;

&lt;p&gt;The rest of the code outside the region is pretty straight forward.  There’s a Dictionary containing attribute name/values and a List&amp;lt;DynamicElement&amp;gt; containing child elements.  Now that I’m writing this it strikes me perhaps this should be a Dictionary itself to reduce lookup times but I leave that as an exercise to the reader (or maybe I’ll update this post at some point… maybe).  When someone attempts to get the value of a property like &lt;em&gt;CustomSettings.SomeValue&lt;/em&gt; I first look in the attributes and then if it doesn’t exist there I look in the child elements.&lt;/p&gt;

&lt;p&gt;And there you have it – dynamic configuration settings in .NET 4!&lt;/p&gt;&lt;img src="http://statichippo.com/blog/aggbug/83.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Noah</dc:creator>
            <guid>http://statichippo.com/blog/archive/2012/01/12/dynamic-configuration-settings-in-net-4.aspx</guid>
            <pubDate>Thu, 12 Jan 2012 15:29:52 GMT</pubDate>
            <comments>http://statichippo.com/blog/archive/2012/01/12/dynamic-configuration-settings-in-net-4.aspx#feedback</comments>
            <wfw:commentRss>http://statichippo.com/blog/comments/commentRss/83.aspx</wfw:commentRss>
            <trackback:ping>http://statichippo.com/blog/services/trackbacks/83.aspx</trackback:ping>
        </item>
        <item>
            <title>Do not take Windows Updates lightly</title>
            <category>.NET Framework</category>
            <category>ASP.NET</category>
            <category>Windows</category>
            <link>http://statichippo.com/blog/archive/2012/01/09/do-not-take-windows-updates-lightly.aspx</link>
            <description>&lt;p&gt;Recently we experienced an odd issue; on an intermittent basis authenticated users would see a non-authenticated view of the page they were on.  A little debugging revealed that each server behaved well in isolation but when the load balancer was in the mix moving requests between servers things got wonky.  Using his mad curl skillz, @andrewmglenn determined that the authentication cookie set from one of our servers was not playing nicely with the others.  This turned out to be a two way street – one server didn’t like the cookies set from the other servers and the others didn’t like the cookie set from this one.&lt;/p&gt;  &lt;p&gt;It turned out this one server had a security update installed not long before we experienced the issue.  The link in Windows Update points to &lt;a href="http://support.microsoft.com/kb/2656351"&gt;http://support.microsoft.com/kb/2656351&lt;/a&gt; and mentions something about a “vulnerability that would allow an unauthenticated remote attacker to compromise your system”.  The update included updated versions of numerous important files including System.Web.dll and aspnet_wp.exe.  But it takes 2 clicks from the support url to actually get to a page with real information on the exploit and the solution taken in the security update.  Over at &lt;a href="http://technet.microsoft.com/en-us/security/bulletin/ms11-100"&gt;http://technet.microsoft.com/en-us/security/bulletin/ms11-100&lt;/a&gt; towards the bottom of the page in the FAQ section there’s a mention of the workaround taken by the update: “The update addresses this vulnerability by correcting how the ASP.NET Framework authenticates users.”&lt;/p&gt;  &lt;p&gt;So it seems that this server is generating and verifying authentication cookie values using a new algorithm!&lt;/p&gt;  &lt;p&gt;The moral of the story is clear and is an important lesson for small shops: do not take Windows Updates lightly.&lt;/p&gt;&lt;img src="http://statichippo.com/blog/aggbug/82.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Noah</dc:creator>
            <guid>http://statichippo.com/blog/archive/2012/01/09/do-not-take-windows-updates-lightly.aspx</guid>
            <pubDate>Mon, 09 Jan 2012 20:00:00 GMT</pubDate>
            <comments>http://statichippo.com/blog/archive/2012/01/09/do-not-take-windows-updates-lightly.aspx#feedback</comments>
            <wfw:commentRss>http://statichippo.com/blog/comments/commentRss/82.aspx</wfw:commentRss>
            <trackback:ping>http://statichippo.com/blog/services/trackbacks/82.aspx</trackback:ping>
        </item>
        <item>
            <title>C9 Lectures: Dr. Erik Meijer&amp;ndash;Functional Programming Fundamentals Playlist</title>
            <category>Education</category>
            <link>http://statichippo.com/blog/archive/2011/10/31/c9-lectures-dr-erik-meijerndashfunctional-programming-fundamentals-playlist.aspx</link>
            <description>&lt;p&gt;&lt;a href="http://billrob.com/"&gt;BillRob&lt;/a&gt; turned me on to these Channel9 Function Programming lectures by Dr. Erik Meijer.  Unfortunately the episodes are really hard to find – I didn’t see a single playlist or search query that returned all 13 episodes.  And reverse engineering their URLs didn’t work either!  So after performing 13 different searches to find every episode I figured I’d post the links here.  Hopefully MSDN will introduce a Course or Playlist feature that gives quick access to multipart series!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://channel9.msdn.com/shows/Going+Deep/Lecture-Series-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-1/"&gt;Chapter 1 of 13&lt;/a&gt;&lt;/p&gt;  &lt;p align="left"&gt;&lt;a href="http://channel9.msdn.com/shows/Going+Deep/Lecture-Series-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-2/"&gt;Chapter 2 of 13&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://channel9.msdn.com/shows/Going+Deep/C9-Lectures-Dr-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-3-of-13/"&gt;Chapter 3 of 13&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://channel9.msdn.com/shows/Going+Deep/C9-Lectures-Dr-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-4-of-13/"&gt;Chapter 4 of 13&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://channel9.msdn.com/shows/Going+Deep/C9-Lectures-Dr-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-5-of-13/"&gt;Chapter 5 of 13&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://channel9.msdn.com/shows/Going+Deep/C9-Lectures-Dr-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-6-of-13/"&gt;Chapter 6 of 13&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://channel9.msdn.com/shows/Going+Deep/C9-Lectures-Dr-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-7-of-13/"&gt;Chapter 7 of 13&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://channel9.msdn.com/shows/Going+Deep/C9-Lectures-Dr-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-8-of-13/"&gt;Chapter 8 of 13&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://channel9.msdn.com/shows/Going+Deep/C9-Lectures-Dr-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-9-of-13/"&gt;Chapter 9 of 13&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://channel9.msdn.com/shows/Going+Deep/C9-Lectures-Dr-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-10-of-13/"&gt;Chapter 10 of 13&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://channel9.msdn.com/shows/Going+Deep/C9-Lectures-Dr-Graham-Hutton-Functional-Programming-Fundamentals-Chapter-11-of-13/"&gt;Chapter 11 of 13&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://channel9.msdn.com/shows/Going+Deep/C9-Lectures-Dr-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-12-of-13/"&gt;Chapter 12 of 13&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://channel9.msdn.com/shows/Going+Deep/C9-Lectures-Dr-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-13-of-13/"&gt;Chapter 13 of 13&lt;/a&gt;&lt;/p&gt;&lt;img src="http://statichippo.com/blog/aggbug/81.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Noah</dc:creator>
            <guid>http://statichippo.com/blog/archive/2011/10/31/c9-lectures-dr-erik-meijerndashfunctional-programming-fundamentals-playlist.aspx</guid>
            <pubDate>Mon, 31 Oct 2011 19:01:39 GMT</pubDate>
            <comments>http://statichippo.com/blog/archive/2011/10/31/c9-lectures-dr-erik-meijerndashfunctional-programming-fundamentals-playlist.aspx#feedback</comments>
            <wfw:commentRss>http://statichippo.com/blog/comments/commentRss/81.aspx</wfw:commentRss>
            <trackback:ping>http://statichippo.com/blog/services/trackbacks/81.aspx</trackback:ping>
        </item>
        <item>
            <title>Graceful degradation via ASP.NET OutputCacheProvider</title>
            <category>ASP.NET</category>
            <link>http://statichippo.com/blog/archive/2011/09/25/graceful-degradation-via-asp-net-outputcacheprovider.aspx</link>
            <description>&lt;p&gt;Like everyone, we never want our site to go down.  Some pages display data and if something happens to the database we’d like at the very least to display old data instead of an error.  In that vain I wrote a proof of concept that might help.  This is not live and may never go live but it tests well and I thought it was interesting enough to post.&lt;/p&gt;  &lt;p&gt;The implementation is based on two interconnected pieces – an OutputCacheProvider and an HttpModule.  The OutputCacheProvider, like the built in output cache provider, is responsible for storing and retrieving cached pages.  In addition, however, it keeps cached pages around past their expiration in case the need arises to render them.  The HttpModule’s responsibility is to handle exceptions and by writing out cached versions of the page regardless of their age.&lt;/p&gt;  &lt;p&gt;The sourcecode is available at &lt;a href="https://github.com/statichippo/Graceful-Degradation-Cache-Provider"&gt;on github&lt;/a&gt; but I’ll step through the initial check version of the code here to better explain what’s going on.&lt;/p&gt;  &lt;h3&gt;GracefulDegradationOutputCacheProvider&lt;/h3&gt;  &lt;p&gt;This is just a standard OutputCacheProvider (OutputCacheProviders were introduced with ASP.NET 4.0.  Check out &lt;a href="http://weblogs.asp.net/gunnarpeipman/archive/2009/11/19/asp-net-4-0-writing-custom-output-cache-providers.aspx"&gt;http://weblogs.asp.net/gunnarpeipman/archive/2009/11/19/asp-net-4-0-writing-custom-output-cache-providers.aspx&lt;/a&gt; for more info).  The interesting piece to note though is that the standard Get method implemented for OutputCacheProvider just calls another Get method that takes a boolean parameter called &lt;em&gt;respectExpiration&lt;/em&gt;.  The “standard” Get method just passes in true for this.  Here’s the code:&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;/// &amp;lt;summary&amp;gt;
/// Gets an item from the cache by key
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="key"&amp;gt;Key to fine&amp;lt;/param&amp;gt;
/// &amp;lt;param name="respectExpiration"&amp;gt;If true, don't return stale results.  This parameter should be true
/// in regular caching cases and false if we're retrieving from cache when an exception occurred&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
internal object Get(string key, bool respectExpiration)
{
    Debug.WriteLine("Cache.Get(" + key + ")");

    CacheItem existing;
    if (!_items.TryGetValue(key, out existing))
        return null;

    if (!respectExpiration)
        return existing.Item;

    if (existing.Expires &amp;gt; DateTime.UtcNow)
        return existing.Item;

    return null;
}&lt;/pre&gt;

&lt;p&gt;as you can see, the &lt;em&gt;respectExpiration&lt;/em&gt; flag is used to override the cache expiration and return the value anyway.  This is used by the:&lt;/p&gt;

&lt;h3&gt;GracefulDegradationCacheModule&lt;/h3&gt;

&lt;p&gt;this just catches the HttpApplications’s Error event and attempts to write the cached output out to the response stream.  There are a couple pieces of interest inside the handler:&lt;/p&gt;

&lt;h5&gt;Finding the provider&lt;/h5&gt;

&lt;p&gt;The handler starts off by finding the GracefulDegradationOutputCacheProvider among the available CacheProviders for the application:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;// Find the GracefulDegredationOutputCacheProvider
foreach (var provider in OutputCache.Providers)
{
    var inMemoryProvider = provider as GracefulDegradationOutputCacheProvider;
    if (inMemoryProvider == null)
        continue;&lt;/pre&gt;

&lt;p&gt;the reason this provider isn’t cached in some field is because this can be modified programmatically and so I just loop every time and attempt to find the provider.&lt;/p&gt;

&lt;h5&gt;Writing the cache out to the response&lt;/h5&gt;

&lt;p&gt;At first I was using a roundabout method to determine an error threshold with a timer firing and clearing error counts – it was pretty awkward.  When I mentioned it to my peers, Joe (&lt;a href="http://twitter.com/#!/joecianflone"&gt;http://twitter.com/#!/joecianflone&lt;/a&gt;) really felt the pain and &lt;a href="http://billrob.com/"&gt;BillRob&lt;/a&gt; came up with the much simpler approach of just writing the response out from the cache on error.  Duh!  With a few helpful hints from Bill, here’s what I came up with:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;var context = HttpContext.Current;
var response = context.Response;
// clear response
response.Clear();

// we don't want anyone caching this old response, right?
response.CacheControl = "no-cache";

var responseBytes = GetResponseBytes(cacheItem, context);
// write out response body
// you can also append some content if you wish,
// perhaps a floating div that tells the user
// the page they're seeing is old
responseBytes.ForEach(x =&amp;gt; 
{
    response.OutputStream.Write(x, 0, x.Length);
});

// Don't want to show the error page (though you
// probably want to alert someone!)
context.ClearError();&lt;/pre&gt;

&lt;p&gt;notice that we explicitly tell clients not to cache this!  Also, as mentioned in the comments, I could see adding some hook here to place some floating div somewhere to let people know what they’re seeing may be stale.  Also, the error is cleared so you probably want to log it somewhere – just because your end user doesn’t see an error doesn’t mean you don’t want to know it happened!&lt;/p&gt;&lt;img src="http://statichippo.com/blog/aggbug/80.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Noah</dc:creator>
            <guid>http://statichippo.com/blog/archive/2011/09/25/graceful-degradation-via-asp-net-outputcacheprovider.aspx</guid>
            <pubDate>Mon, 26 Sep 2011 00:03:27 GMT</pubDate>
            <comments>http://statichippo.com/blog/archive/2011/09/25/graceful-degradation-via-asp-net-outputcacheprovider.aspx#feedback</comments>
            <wfw:commentRss>http://statichippo.com/blog/comments/commentRss/80.aspx</wfw:commentRss>
            <trackback:ping>http://statichippo.com/blog/services/trackbacks/80.aspx</trackback:ping>
        </item>
        <item>
            <title>Testing SyntaxHighlighter</title>
            <category>Misc</category>
            <link>http://statichippo.com/blog/archive/2011/09/12/testing-syntaxhighlighter.aspx</link>
            <description>&lt;p&gt;So I found what looks like it might be a good solution to some issues I’m having with syntax highlighting on my blog.  It’s a combination of a script called SyntaxHighlighter (&lt;a href="http://alexgorbatchev.com/SyntaxHighlighter/"&gt;http://alexgorbatchev.com/SyntaxHighlighter/&lt;/a&gt;) and a Windows LiveWriter plugin called PreCode Snippet (&lt;a href="http://precode.codeplex.com/"&gt;http://precode.codeplex.com/&lt;/a&gt;).  So here’s a little test to make sure it works well with both C# and F# (I found the F# brush for SyntaxHighligher over at Steve Gilham’s blog -&lt;a href="http://stevegilham.blogspot.com/2009/10/syntaxhighlighter-20-brushes-for-f-and.html"&gt; http://stevegilham.blogspot.com/2009/10/syntaxhighlighter-20-brushes-for-f-and.html&lt;/a&gt;)&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;public class Foo 
{
    public object Bar { get; set; }
    private object _baz;
    public void SetBaz(object o)
    {
        if (o == null)
            throw new ArgumentNullException();
        _baz = o;
    }    
}&lt;/pre&gt;

&lt;pre class="brush: fsharp;"&gt;let rec fib x =
    if x = 0 then
        0
    elif x = 1 then
        1
    else
        fib (x-1) + fib (x-1)&lt;/pre&gt;

&lt;p&gt;So it seems that when I press Enter to exit the PreCode Snippet that it just creates a new snippet and I have to go into the Source and type something outside of the &amp;lt;pre&amp;gt; tag so that I can go back to Edit mode and start typing some regular text.&lt;/p&gt;

&lt;p&gt;&lt;strike&gt;Now to publish and see how it looks online.&lt;/strike&gt; Took a couple tweaks but it looks pretty good!&lt;/p&gt;&lt;img src="http://statichippo.com/blog/aggbug/79.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Noah</dc:creator>
            <guid>http://statichippo.com/blog/archive/2011/09/12/testing-syntaxhighlighter.aspx</guid>
            <pubDate>Mon, 12 Sep 2011 15:16:49 GMT</pubDate>
            <comments>http://statichippo.com/blog/archive/2011/09/12/testing-syntaxhighlighter.aspx#feedback</comments>
            <wfw:commentRss>http://statichippo.com/blog/comments/commentRss/79.aspx</wfw:commentRss>
            <trackback:ping>http://statichippo.com/blog/services/trackbacks/79.aspx</trackback:ping>
        </item>
        <item>
            <title>F# and Entity Framework, not there yet</title>
            <link>http://statichippo.com/blog/archive/2011/08/07/f-and-entity-framework-not-there-yet.aspx</link>
            <description>&lt;p&gt;Based on &lt;a href="http://blogs.msdn.com/b/visualstudio/archive/2011/04/04/f-code-first-development-with-entity-framework-4-1.aspx" target="_blank"&gt;this article&lt;/a&gt; on MSDN I decided to code the data layer for an app in F#.  After a few weeks of hobby time coding, I don’t believe that EF via F# is a viable solution yet.  Here’s why:&lt;/p&gt;  &lt;p&gt;&lt;em&gt;NOTE: Windows Live Writer is crashing constantly on me.  I’ve got 2 reasons so far and may update this post with more when Live Writer starts behaving (going to restart at some point this week I suppose) or I find a more stable editor.&lt;/em&gt;&lt;/p&gt;  &lt;h4&gt;1. No &lt;em&gt;protected&lt;/em&gt; keyword&lt;/h4&gt;  &lt;p&gt;Because the Entity Framework’s proxy classes inherit from their base classes (and because they do not support setting private properties of their ancestors), the &lt;em&gt;protected&lt;/em&gt; keyword becomes especially important.  &lt;em&gt;Protected&lt;/em&gt; becomes a way of creating properties that can be set only by the class itself and by Entity Framework’s proxy classes.  I’m especially fond of this in constructors.  Take the following code snippet:&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Person&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; FirstName { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; LastName { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Person(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; firstName, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; lastName)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;         FirstName = firstName;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;         LastName = lastName;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Person() {}&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This requires client code to specify a first and last name for a &lt;em&gt;Person&lt;/em&gt; while still allowing Entity Framework to construct a new &lt;em&gt;Person&lt;/em&gt; object via its default constructor (a requirement) before setting the properties.  This is also really useful for lists and such – by making them &lt;em&gt;protected&lt;/em&gt; you can ensure that they are never null and wrap list inserts inside a method like so:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; ...&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; people { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AddPerson(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; name)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// business logic around the name&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;     people.Add(name);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt; ...&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Since F# doesn’t support the &lt;em&gt;protected&lt;/em&gt; keyword, there’s no alternative to generating a public default constructor and exposing your lists getter and setter for all.&lt;/p&gt;

&lt;h4&gt;2. Awkward &lt;em&gt;null&lt;/em&gt; support&lt;/h4&gt;

&lt;p&gt;When writing functional code, the lack of implicit support for &lt;em&gt;null&lt;/em&gt; values is very useful.  However, Entity Framework is used to interact with a database – somewhere where &lt;em&gt;nulls&lt;/em&gt; are commonplace and very useful.  I wrote a blog post about one issue with this (&lt;a href="http://statichippo.com/archive/2011/07/28/f-system-linq-extensions-and-the-case-of-the-missing.aspx" target="_blank"&gt;F#, System.Linq extensions and the case of the missing null&lt;/a&gt;) but there are others including lack of support for Nullable&amp;lt;T&amp;gt; (in case you think you’re unfamiliar with Nullable&amp;lt;T&amp;gt;, you’re probably not.  You may never have written &lt;em&gt;Nullable&lt;/em&gt; in your code -- the ? in C# is syntactic sugar around it.  So if you’ve ever written &lt;em&gt;int? &lt;/em&gt;in C#, you’ve used Nullable&amp;lt;int&amp;gt;).  F# has it’s own way of achieving something similar to Nullable&amp;lt;T&amp;gt; called Option&amp;lt;T&amp;gt; but it’s based on F# Discriminated Unions and is not supported by Entity Framework.  &lt;/p&gt;

&lt;p&gt;The biggest use case for Nullable&amp;lt;T&amp;gt; in Entity Framework in my opinion is with DateTime.  DateTime is a value type and cannot be null.  But null datetime values in the database are a frequent occurrence usually meant to signify that something has never taken place.  Take the following code:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Email&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt; ...&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; DateTime? DateSent { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt; ...&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;In this case, the &lt;em&gt;Email&lt;/em&gt; class defines a &lt;em&gt;DateSent&lt;/em&gt; property that presumably will be &lt;em&gt;null&lt;/em&gt; until the email is actually sent.  This makes a lot of sense in the database and even in C# but doesn’t work out so well in F#.  First of all there’s the syntactic sugar in C#.  Consider the same code written in F#:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; open System&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; type Email =&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt; ...&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     let mutable m_dateSent = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Nullable&amp;lt;DateTime&amp;gt;()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;     member &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.DateSent with get () = m_dateSent &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;                                 and set v = m_dateSent &amp;lt;- v&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt; ...&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Aside from the verbosity, check out this snippet that &lt;em&gt;doesn’t compile&lt;/em&gt; (if you’re not familiar with the syntax, I’m using the &lt;a href="http://blogs.msdn.com/b/dsyme/archive/2009/10/23/a-quick-refresh-on-query-support-in-the-f-power-pack.aspx" target="_blank"&gt;F# PowerPack Linq extensions&lt;/a&gt;):&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; let unsentEmails = query &amp;lt;@ seq { &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; context.Emails &lt;span style="color: #0000ff"&gt;do&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt;                                     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; e.EmailSent = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; then&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;                                         &lt;span style="color: #0000ff"&gt;yield&lt;/span&gt; e&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;                                  } @&amp;gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Can you guess why that won’t compile?  Line 2 checks EmailSent, which is a Nullable&amp;lt;DateTime&amp;gt; against &lt;em&gt;null&lt;/em&gt; which is not permitted a &lt;em&gt;null&lt;/em&gt; value.  You can get around this by changing that line to &lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; e.EmailSent.HasValue = &lt;span style="color: #0000ff"&gt;false&lt;/span&gt; then&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;However, the outputted SQL (using the default, MSSQL connector) from this line is far worse than the equivalent in C# (using the “= null”).  In C#, the expected SQL is outputted – including a &lt;em&gt;where&lt;/em&gt; clause that checks for the column against &lt;em&gt;null &lt;/em&gt;which allows the use of an index in MSSQL (although not for mySQL which is another conversation altogether!).  The F# code, checking the &lt;em&gt;HasValue&lt;/em&gt; property of the Nullable&amp;lt;DateTime&amp;gt;,  generates some awful SQL in the &lt;em&gt;where&lt;/em&gt; clause using CASE and CAST seemingly just to annoy by preventing the use of indexes:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;WHERE&lt;/span&gt; 0 = &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;CASE&lt;/span&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;WHEN&lt;/span&gt; ([Extent1].[EmailSent] &lt;span style="color: #0000ff"&gt;IS&lt;/span&gt; &lt;span style="color: #0000ff"&gt;NOT&lt;/span&gt; &lt;span style="color: #0000ff"&gt;NULL&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;THEN&lt;/span&gt; &lt;span style="color: #0000ff"&gt;cast&lt;/span&gt;(1 &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bit&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;WHEN&lt;/span&gt; ([Extent1].[EmailSent] &lt;span style="color: #0000ff"&gt;IS&lt;/span&gt; &lt;span style="color: #0000ff"&gt;NULL&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;THEN&lt;/span&gt; &lt;span style="color: #0000ff"&gt;cast&lt;/span&gt;(0 &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bit&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;  &lt;span style="color: #0000ff"&gt;END&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;&lt;img src="http://statichippo.com/blog/aggbug/78.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Noah</dc:creator>
            <guid>http://statichippo.com/blog/archive/2011/08/07/f-and-entity-framework-not-there-yet.aspx</guid>
            <pubDate>Sun, 07 Aug 2011 04:51:47 GMT</pubDate>
            <comments>http://statichippo.com/blog/archive/2011/08/07/f-and-entity-framework-not-there-yet.aspx#feedback</comments>
            <wfw:commentRss>http://statichippo.com/blog/comments/commentRss/78.aspx</wfw:commentRss>
            <trackback:ping>http://statichippo.com/blog/services/trackbacks/78.aspx</trackback:ping>
        </item>
        <item>
            <title>F#, System.Linq extensions and the case of the missing null</title>
            <category>f#</category>
            <category>Entity Framework</category>
            <category>.NET Framework</category>
            <link>http://statichippo.com/blog/archive/2011/07/28/f-system-linq-extensions-and-the-case-of-the-missing.aspx</link>
            <description>&lt;p&gt;I posted a question to StackOverflow yesterday (&lt;a href="http://stackoverflow.com/questions/6847203/ef4-1-and-f-how-to-deal-with-values"&gt;http://stackoverflow.com/questions/6847203/ef4-1-and-f-how-to-deal-with-values&lt;/a&gt;) and will describe the issue and resolution in this post.&lt;/p&gt;    &lt;p&gt;F# is a funny language in that it is a functional (I suppose it’s multi-paradigm but very strong emphasis on functional) language built on the .NET platform which has a very different style as a whole.  I had an interesting issue the other day where I noticed a &lt;em&gt;null&lt;/em&gt; value at runtime being returned from a .NET component in a place that F# was certain &lt;em&gt;null&lt;/em&gt; values could not exist. &lt;/p&gt;  &lt;p&gt;In my case this was Entity Framework.  I followed &lt;a href="http://blogs.msdn.com/b/jackhu/archive/2011/04/01/f-code-first-development-with-entity-framework-4-1.aspx" target="_blank"&gt;this walkthrough&lt;/a&gt; to create F# types that mapped to my database using Entity Framework Code First.  I wrote a query that ended in .FirstOrDefault() and here is where the problem started:&lt;/p&gt;  &lt;p&gt;(sorry I don’t have a good F# source highlighter for Live Writer – any suggestions?)&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; let result = context&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt;             .SearchResults&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;             .Where((fun (r:SearchResult) -&amp;gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;                     r.Program = request.Program))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;             .OrderByDescending((fun r -&amp;gt; r.AcquisitionDate))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;             .FirstOrDefault()&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Now .FirstOrDefault() is implemented such that it returns either the first element if one exists, or default(T) if not.  Well my &lt;em&gt;SearchResult&lt;/em&gt; type is defined in F# and is just a regular class so the &lt;em&gt;default(typeof(SearchResult))&lt;/em&gt; is equal to &lt;em&gt;null&lt;/em&gt;.  However, F# doesn’t allow nulls be default – due to its functional nature it doesn’t by default support &lt;em&gt;null &lt;/em&gt;values (which I’ve come to really appreciate when I’m writing ‘pure’ F#).  So when the database has no data, what value do you think is bound to &lt;em&gt;result&lt;/em&gt;?&lt;/p&gt;

&lt;p&gt;If you guessed&lt;em&gt; null&lt;/em&gt; you were right.  But I just said that F# doesn’t support &lt;em&gt;null&lt;/em&gt;.  So the following code does not compile:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; match result with&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt;     | &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; -&amp;gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;                () &lt;span style="color: #008000"&gt;// do nothing since this doesn't compile anyway&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     | price -&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;                () // &lt;span style="color: #0000ff"&gt;do&lt;/span&gt; nothing since &lt;span style="color: #0000ff"&gt;this&lt;/span&gt; doesn't compile anyway&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;the compilation error states&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;the type 'SearchResult' does not have 'null' as a proper value&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Interesting.  So SearchResult doesn’t support &lt;em&gt;null&lt;/em&gt;.  Even more interesting is if you comment out the bad code and run it you’ll see that &lt;em&gt;result&lt;/em&gt; which is of type &lt;em&gt;SearchResult&lt;/em&gt; is indeed bound to &lt;em&gt;null&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;It seems to me that in a world of uncertainty – a world of mixed paradigms -- F# assumes a convention.  F# assumes that every component is as functionally pure as it is – though it is made to interoperate with components that are known not to be.&lt;/p&gt;

&lt;p&gt;It turns out that the fix to this is pretty simple.  As stated in the first paragraph in the &lt;a href="http://msdn.microsoft.com/en-us/library/dd233197.aspx" target="_blank"&gt;MSDN article on nulls in F#&lt;/a&gt;, F# has an AllowNullLiteral attribute.  I decorated my EF types with this and then the compiler allowed me to compare my &lt;em&gt;results&lt;/em&gt; value to &lt;em&gt;null&lt;/em&gt;.  How imperative!&lt;/p&gt;&lt;img src="http://statichippo.com/blog/aggbug/77.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Noah</dc:creator>
            <guid>http://statichippo.com/blog/archive/2011/07/28/f-system-linq-extensions-and-the-case-of-the-missing.aspx</guid>
            <pubDate>Thu, 28 Jul 2011 20:40:18 GMT</pubDate>
            <comments>http://statichippo.com/blog/archive/2011/07/28/f-system-linq-extensions-and-the-case-of-the-missing.aspx#feedback</comments>
            <wfw:commentRss>http://statichippo.com/blog/comments/commentRss/77.aspx</wfw:commentRss>
            <trackback:ping>http://statichippo.com/blog/services/trackbacks/77.aspx</trackback:ping>
        </item>
        <item>
            <title>Error 52</title>
            <category>Misc</category>
            <link>http://statichippo.com/blog/archive/2011/05/06/error-52.aspx</link>
            <description>&lt;p&gt;I get the following error on build intermittently: &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Error 52 It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level.  This error can be caused by a virtual directory not being configured as an application in IIS. C:\Work\…\web.config 98 Frontend&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I get it infrequently enough that I never remember the fix for it.  I always Google it and come up with the same links – they all imply it’s because of a problem with some configuration.  For me it’s not a configuration problem.  If I delete the \obj directory and rebuild that fixes it.  Go figure.&lt;/p&gt;&lt;img src="http://statichippo.com/blog/aggbug/76.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Noah</dc:creator>
            <guid>http://statichippo.com/blog/archive/2011/05/06/error-52.aspx</guid>
            <pubDate>Fri, 06 May 2011 18:10:22 GMT</pubDate>
            <comments>http://statichippo.com/blog/archive/2011/05/06/error-52.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://statichippo.com/blog/comments/commentRss/76.aspx</wfw:commentRss>
            <trackback:ping>http://statichippo.com/blog/services/trackbacks/76.aspx</trackback:ping>
        </item>
        <item>
            <title>Next up: F#</title>
            <category>Misc</category>
            <category>f#</category>
            <link>http://statichippo.com/blog/archive/2011/04/29/Next-up-F.aspx</link>
            <description>&lt;p&gt;The next language I’ll be learning will be F#.  I just started and have already written my first stack overflow!  But it taught me a lesson about the order of precedents in F#.&lt;/p&gt;  &lt;p&gt;I was writing my first real function, one that wasn’t pre-written in the tutorials I was using (at least not that I got up to yet!): Fibonacci.  I started with&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; let rec fib x =&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; 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: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; x = 0 then&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;         0&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; 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: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     elif x = 1 then&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;         1&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; 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: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;         (fib x-1)+(fib x-2)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; 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: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;  &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt; printfn &lt;span style="color: #006080"&gt;"fib 10 is %A"&lt;/span&gt; (fib 10)&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;and that crashed the interpreter!  can you spot the problem?&lt;/p&gt;

&lt;p&gt;line 7 does this:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;compute fib x&lt;/li&gt;

  &lt;li&gt;subtract 1 from that&lt;/li&gt;

  &lt;li&gt;compute fib x&lt;/li&gt;

  &lt;li&gt;subtract 2 from that&lt;/li&gt;

  &lt;li&gt;add the two together&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I should have written&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; (fib(x-1))+(fib(x-2))&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;I’m learning here!&lt;/p&gt;

&lt;p&gt;The next step, using match patterns instead of if’s.  And Matthew Podwysocki’s got a great write up of that over &lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/03/17/adventures-in-f-f-101-part-5-pattern-matching.aspx" target="_blank"&gt;here&lt;/a&gt;!  Too bad he solved my Fibonacci problem.  Now I’ll have to come up with another problem to really learn the language.  Any suggestions?&lt;/p&gt;&lt;img src="http://statichippo.com/blog/aggbug/75.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Noah</dc:creator>
            <guid>http://statichippo.com/blog/archive/2011/04/29/Next-up-F.aspx</guid>
            <pubDate>Fri, 29 Apr 2011 05:11:00 GMT</pubDate>
            <comments>http://statichippo.com/blog/archive/2011/04/29/Next-up-F.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://statichippo.com/blog/comments/commentRss/75.aspx</wfw:commentRss>
            <trackback:ping>http://statichippo.com/blog/services/trackbacks/75.aspx</trackback:ping>
        </item>
    </channel>
</rss>
