<?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:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Chui's counterpoint</title>
	<atom:link href="http://www.redmountainsw.com/wordpress/feed" rel="self" type="application/rss+xml" />
	<link>http://www.redmountainsw.com/wordpress</link>
	<description>pulling the rug</description>
	<lastBuildDate>Thu, 02 Sep 2010 08:20:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Mock up apps on the iPad</title>
		<link>http://www.redmountainsw.com/wordpress/archives/mock-up-apps-on-the-ipad</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/mock-up-apps-on-the-ipad#comments</comments>
		<pubDate>Thu, 02 Sep 2010 08:20:50 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1049</guid>
		<description><![CDATA[Review of Mock up / wireframe applications on the iPad
Exports X-code

dapp $9.99 iPhone only
Interface HD $9.99

Stencils/Sketching only

AppLayout HD $3.99
iMockups
Omnigraffle
Sketchy
AppDesigner HD $0.99

]]></description>
			<content:encoded><![CDATA[<p><strong>Review of Mock up / wireframe applications on the iPad</strong></p>
<p>Exports X-code</p>
<ul>
<li><a href="http://itunes.apple.com/us/app/dapp/id370888555?mt=8">dapp</a> $9.99 iPhone only</li>
<li><a href="http://itunes.apple.com/us/app/interface-hd/id376554941?mt=8">Interface HD</a> $9.99</li>
</ul>
<p>Stencils/Sketching only</p>
<ul>
<li><a href="http://itunes.apple.com/us/app/app-layout/id384495330?mt=8">AppLayout HD</a> $3.99</li>
<li><a href="http://itunes.apple.com/us/app/imockups-for-ipad/id364885913?mt=8">iMockups</a></li>
<li><a href="http://itunes.apple.com/us/app/omnigraffle/id363225984?mt=8">Omnigraffle</a></li>
<li><a href="http://itunes.apple.com/us/app/omnigraffle/id363225984?mt=8">Sketchy</a></li>
<li><a href="http://itunes.apple.com/us/app/app-designer-hd/id372714220?mt=8">AppDesigner HD</a> $0.99</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/mock-up-apps-on-the-ipad/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight &#8211; Element is already the child of another element</title>
		<link>http://www.redmountainsw.com/wordpress/archives/silverlight-element-is-already-the-child-of-another-element</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/silverlight-element-is-already-the-child-of-another-element#comments</comments>
		<pubDate>Mon, 30 Aug 2010 22:45:48 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1046</guid>
		<description><![CDATA[Mike Talbot of Alterian has a clever way of taking most of the guesswork figuring out which piece of XAML is misbehaving, by progressively stripping out child nodes until the error is gone.
In his own words:
When the file has a problem it starts to prune out nodes in the XAML one XML node at a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://whydoidoit.com/">Mike Talbot</a> of Alterian has a clever way of taking most of the guesswork figuring out which piece of XAML is misbehaving, by progressively stripping out child nodes until the error is gone.</p>
<p>In his own words:</p>
<blockquote><p>When the file has a problem it starts to prune out nodes in the XAML one XML node at a time (I mean it puts back nodes that didn’t solve the problem and tries the next in sequence).  It does this starting with the nodes that have no children, then the ones with 1, 2 and so on, until it has to remove the entire body – hopefully the error is found long before this.  Using this technique the algorithm tries to give you the most tightly isolated area of the Xaml to focus on.  </p>
<p>When it identifies a node, it checks whether removing any attribute helps and returns this in addition to the offending XAML if it resolves the issue. </p></blockquote>
<p>Link: <a href="http://whydoidoit.com/2010/08/30/debug-xaml-element-is-already-the-child-of-another-element/">XAML element is already the child of another element</a> error over at his post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/silverlight-element-is-already-the-child-of-another-element/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone development on Windows</title>
		<link>http://www.redmountainsw.com/wordpress/archives/iphone-development-on-windows</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/iphone-development-on-windows#comments</comments>
		<pubDate>Wed, 25 Aug 2010 01:07:26 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1044</guid>
		<description><![CDATA[(Please email me if you want your SDK included, or post a comment)

Airplay SDK
DragonFire SDK &#8211; provides a BuildCenter
WinChain (free)

Other interesting ones

Appcelerator Titanium WebKit wrapper (requires Mac?)
PhoneGap
Unity 3D

]]></description>
			<content:encoded><![CDATA[<p>(Please <a href="mailto:teyc@cognoware.com">email</a> me if you want your SDK included, or post a comment)</p>
<ul>
<li><a href="http://www.airplaysdk.com/">Airplay SDK</a></li>
<li><a href="http://www.dragonfiresdk.com">DragonFire SDK</a> &#8211; provides a BuildCenter</li>
<li>WinChain (free)</li>
</ul>
<p>Other interesting ones</p>
<ul>
<li><a href="http://www.appcelerator.com/">Appcelerator Titanium</a> WebKit wrapper (requires Mac?)</li>
<li><a href="http://www.phonegap.com/">PhoneGap</a></li>
<li><a rel="nofollow" href="http://unity3d.com/" target="_blank">Unity 3D</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/iphone-development-on-windows/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wrong user name password at imap.gmail.com</title>
		<link>http://www.redmountainsw.com/wordpress/archives/ipad-mai</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/ipad-mai#comments</comments>
		<pubDate>Mon, 23 Aug 2010 07:33:44 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1040</guid>
		<description><![CDATA[If you suspect an account has been locked out due to mistyped passwords, the account can be unlocked by going to a captcha page.
https://www.google.com/accounts/UnlockCaptcha
or Google Apps for Domain
https://www.google.com/a/[yourdomain]/accounts/UnlockCaptcha
e.g.
https://www.google.com/a/projectliftoff.com/UnlockCaptca
]]></description>
			<content:encoded><![CDATA[<p>If you suspect an account has been locked out due to mistyped passwords, the account can be unlocked by going to a captcha page.</p>
<p><a href="https://www.google.com/accounts/UnlockCaptcha">https://www.google.com/accounts/UnlockCaptcha</a></p>
<p>or <b>Google Apps for Domain</b></p>
<p>https://www.google.com/a/[yourdomain]/accounts/UnlockCaptcha</p>
<p>e.g.</p>
<p>https://www.google.com/a/projectliftoff.com/UnlockCaptca</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/ipad-mai/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Binding to DatePicker in Caliburn.Micro</title>
		<link>http://www.redmountainsw.com/wordpress/archives/autobind-datepicker-caliburn</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/autobind-datepicker-caliburn#comments</comments>
		<pubDate>Thu, 19 Aug 2010 07:32:06 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[caliburn]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1038</guid>
		<description><![CDATA[I&#8217;m running Silverlight, and I have a DatePicker control which I wish to bind automatically.
Recipe

        Caliburn.Micro.ConventionManager.AddElementConvention(Of DatePicker)(DatePicker.SelectedDateProperty, &#34;SelectedDate&#34;, &#34;SelectedDateChanged&#34;)
        Caliburn.Micro.ViewModelBinder.Bind(_reportFilterVm, Me.ReportFilter, Nothing)

]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m running Silverlight, and I have a DatePicker control which I wish to bind automatically.</p>
<p><strong>Recipe</strong></p>
<pre class="brush: vb">
        Caliburn.Micro.ConventionManager.AddElementConvention(Of DatePicker)(DatePicker.SelectedDateProperty, &quot;SelectedDate&quot;, &quot;SelectedDateChanged&quot;)
        Caliburn.Micro.ViewModelBinder.Bind(_reportFilterVm, Me.ReportFilter, Nothing)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/autobind-datepicker-caliburn/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Passing arrays to SQL statements safely</title>
		<link>http://www.redmountainsw.com/wordpress/archives/passing-arrays-to-sql-statements-safely</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/passing-arrays-to-sql-statements-safely#comments</comments>
		<pubDate>Tue, 17 Aug 2010 12:18:27 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[database]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1036</guid>
		<description><![CDATA[SQL Parameters only accepts scalar values. What if you wanted to pass an array as an IN criteria?
Here&#8217;s a workaround, without using stored procs. Just IFormatter magic.
You will be able to to this:

Dim ids(0 to 3) as integer
ids(0) = 32
ids(1) = 34
ids(2) = 42
ids(3) = 48
statement = SqlFormatter.Format(&#34;SELECT * FROM Persons WHERE PersonId in {0:f0}&#34;, [...]]]></description>
			<content:encoded><![CDATA[<p>SQL Parameters only accepts scalar values. What if you wanted to pass an array as an IN criteria?</p>
<p>Here&#8217;s a workaround, without using stored procs. Just IFormatter magic.</p>
<p>You will be able to to this:</p>
<pre class="brush: vb">
Dim ids(0 to 3) as integer
ids(0) = 32
ids(1) = 34
ids(2) = 42
ids(3) = 48
statement = SqlFormatter.Format(&quot;SELECT * FROM Persons WHERE PersonId in {0:f0}&quot;, ids)
</pre>
<pre class="brush: vb">
Public Class SqlFormatter
    Implements IFormatProvider, ICustomFormatter

    Public Shared Function Format(ByVal formatString, ByVal ParamArray args()) As String
        Return String.Format(New SqlFormatter(), formatString, args)
    End Function

    Public Function GetFormat(ByVal formatType As System.Type) As Object Implements System.IFormatProvider.GetFormat
        If formatType Is GetType(ICustomFormatter) Then
            Return Me
        Else
            Return Nothing
        End If
    End Function

    Public Function Format(ByVal fmt As String, ByVal arg As Object, ByVal formatProvider As System.IFormatProvider) As String Implements System.ICustomFormatter.Format
        Dim thisFmt As String = String.Empty
        If Not String.IsNullOrEmpty(fmt) Then
            thisFmt = CStr(If(fmt.Length &gt; 1, fmt.Substring(0, 1), fmt))
        End If

        If Not TypeOf (arg) Is String AndAlso TypeOf (arg) Is IEnumerable Then
            Dim sb As New List(Of String)
            If fmt.ToUpper.Equals(&quot;N&quot;) Then fmt = &quot;f&quot;
            For Each obj In arg
                If obj Is Nothing Then
                    sb.Add(&quot;Null&quot;)
                Else
                    sb.Add(String.Format(Me, &quot;{0:&quot; + fmt + &quot;}&quot;, obj))
                End If
            Next
            Return &quot;(&quot; + String.Join(&quot;, &quot;, sb) + &quot;)&quot;
        Else
            Dim formatted As String
            Select Case thisFmt.ToUpper()
                Case &quot;C&quot;
                    &#039; Escape strings
                    formatted = &quot;&#039;&quot; + CType(arg, String).Replace(&quot;&#039;&quot;, &quot;&#039;&#039;&quot;) + &quot;&#039;&quot;
                Case &quot;D&quot;
                    &#039; Date
                    formatted = &quot;&#039;&quot; + String.Format(&quot;{0:Y}-{0:M}-{0:D}&quot;, arg) + &quot;&#039;&quot;
                Case Else
                    formatted = HandleOtherFormats(fmt, arg)
            End Select
            Return formatted
        End If

    End Function

    Private Function HandleOtherFormats(ByVal fmt As String, ByVal arg As Object) As String
        If TypeOf arg Is IFormattable Then
            Return DirectCast(arg, IFormattable).ToString(fmt, CultureInfo.CurrentCulture)
        ElseIf arg IsNot Nothing Then
            Return arg.ToString()
        Else
            Return String.Empty
        End If
    End Function
End Class
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/passing-arrays-to-sql-statements-safely/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why Microsoft Lightswitch is not MS Access.</title>
		<link>http://www.redmountainsw.com/wordpress/archives/why-microsoft-lightswitch-is-not-ms-access</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/why-microsoft-lightswitch-is-not-ms-access#comments</comments>
		<pubDate>Mon, 16 Aug 2010 01:49:19 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[MS Access]]></category>
		<category><![CDATA[lightswitch]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1034</guid>
		<description><![CDATA[There is a great deal of concern among developers that Visual Studio Lightswitch will dumb down programming. Donald Belcham, for example, suggests that Lightswitch is going to be like MS Access with all it&#8217;s bad practices.
To the professional developers that read this blog (most of you I’m guessing), prepare to move your hatred and loathing [...]]]></description>
			<content:encoded><![CDATA[<p>There is a great deal of concern among developers that <a href="http://www.microsoft.com/visualstudio/en-us/lightswitch">Visual Studio Lightswitch</a> will dumb down programming. Donald Belcham, for example, suggests that <a href="http://www.igloocoder.com/archive/2010/08/04/microsoft.data.dll-and-lightswitch.aspx">Lightswitch is going to be like MS Access</a> with all it&#8217;s bad practices.</p>
<blockquote><p>To the professional developers that read this blog (most of you I’m guessing), prepare to move your hatred and loathing from MS Access to LightSwitch.</p></blockquote>
<p>I believe this view misrepresents what Lightswitch is.</p>
<p>Lightswitch is a declarative framework to perform databinding straight-through from presentation layer to storage layer, with proper extension points to support validation at the business object layer. It is a distillation of existing framework practices. For instance, based on a Lightswitch spec, there is no reason why one couldn&#8217;t build it on top of NHibernate. </p>
<p>In fact, Lightswitch is so declarative that the same spec be deployed against an Azure database, as well as one on SQL Server. It is sufficiently declarative that it can run on the desktop browser as well as fit in the form factor of a smartphone.  This is a million miles away from dragging and dropping components, and wiring up event handlers. </p>
<p>This is why I, personally am excited about Lightswitch.</p>
<p>Lightswitch is not a library. It is an application framework for data-oriented applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/why-microsoft-lightswitch-is-not-ms-access/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>FAIL: Microsoft wedges own app by sending bad data from the server</title>
		<link>http://www.redmountainsw.com/wordpress/archives/microsoft-wedges-messenger</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/microsoft-wedges-messenger#comments</comments>
		<pubDate>Wed, 11 Aug 2010 23:05:22 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[fail]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/archives/microsoft-wedges-their-own-app-by-sending-bad-data-from-the-server</guid>
		<description><![CDATA[Microsoft managed to brick MSN Messenger rendering it not startable because the server sent corrupted configuration data to the client, which the client subsequently stores in the registry. I had to remotely dial in to my parent&#8217;s PC to fix this.
A fix for MSN Messenger crashing on start-up is here:

Start > Run > type &#8220;regedit&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>Microsoft managed to brick MSN Messenger rendering it not startable because the server sent corrupted configuration data to the client, which the client subsequently stores in the registry. I had to remotely dial in to my parent&#8217;s PC to fix this.</p>
<p>A <a href="http://social.answers.microsoft.com/Forums/en-US/w7programs/thread/0af4625a-99be-469a-958e-22292cedd0fb">fix for MSN Messenger crashing on start-up</a> is here:</p>
<blockquote><p>
Start > Run > type &#8220;regedit&#8221; and hit ok.<br />
In the registry editor, navigate to:<br />
HKEY_CURRENT_USERSoftwareMicrosoftMSNMessengerPerPassportSettings </p>
<p>Under &#8220;PerPassportSettings&#8221;, you may have multiple entries with numbers representing each Live account you&#8217;ve logged in with. In each (or if you only have one), expand the numbered key and look for the string &#8220;UTL&#8221;. delete  the value within &#8220;UTL&#8221;. </p>
<p>After the UTL value has been cleared from each Passport, your Windows Live Messenger should open without crashing. </p>
<p><em>The UTL value contains various bits of XML data related to your Live account. It would seem in the past week especially, there&#8217;s been a small server glitch resulting in &#8220;bad data&#8221; being stored in UTL. This &#8220;bad data&#8221; causes Messenger to crash on startup. </em> The data in UTL will be restored with correct data on your next login.</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/microsoft-wedges-messenger/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WCF Ria Services Composition</title>
		<link>http://www.redmountainsw.com/wordpress/archives/wcf-ria-services-composition</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/wcf-ria-services-composition#comments</comments>
		<pubDate>Wed, 11 Aug 2010 12:22:52 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[wcf]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1023</guid>
		<description><![CDATA[Download VS2010 project:
WcfComposition.zip
Sometimes, MSDN gives buggy information. If you are using Composition, there are a number of calisthenics required to make this thing work. 




namespace WcfComposition.Web
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using [...]]]></description>
			<content:encoded><![CDATA[<p><b>Download VS2010 project</b>:<br />
<a href='http://www.redmountainsw.com/wordpress/wp-content/uploads/WcfComposition.zip'>WcfComposition.zip</a></p>
<p>Sometimes, MSDN gives buggy information. If you are using Composition, there are a number of calisthenics required to make this thing work. </p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<link rel="stylesheet" href="http://www.manoli.net/csharpformat/csharp.css"></link>
<pre class="csharpcode">

<span class="kwrd">namespace</span> WcfComposition.Web
{
    <span class="kwrd">using</span> System;
    <span class="kwrd">using</span> System.Collections.Generic;
    <span class="kwrd">using</span> System.ComponentModel;
    <span class="kwrd">using</span> System.ComponentModel.DataAnnotations;
    <span class="kwrd">using</span> System.Data;
    <span class="kwrd">using</span> System.Linq;
    <span class="kwrd">using</span> System.ServiceModel.DomainServices.EntityFramework;
    <span class="kwrd">using</span> System.ServiceModel.DomainServices.Hosting;
    <span class="kwrd">using</span> System.ServiceModel.DomainServices.Server;
    <span class="kwrd">using</span> System.Data.Objects.DataClasses;
    <span class="kwrd">using</span> System.Data.Objects;
    <span class="kwrd">using</span> System.Linq.Expressions;
    <span class="kwrd">using</span> System.Reflection;
    <span class="kwrd">using</span> System.ServiceModel.DomainServices;

    <span class="rem">// Implements application logic using the CompositionEntities context.</span>
    <span class="rem">// TODO: Add your application logic to these methods or in additional methods.</span>
    <span class="rem">// TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access</span>
    <span class="rem">// Also consider adding roles to restrict access as appropriate.</span>
    <span class="rem">// [RequiresAuthentication]</span>
    [EnableClientAccess()]
    <span class="kwrd">public</span> <span class="kwrd">class</span> OrdersService : LinqToEntitiesDomainService&lt;CompositionEntities&gt;
    {

        <span class="kwrd">public</span> IQueryable&lt;CustomerOrder&gt; GetCustomerOrders()
        {
            <span class="kwrd">return</span> <span class="kwrd">this</span>.ObjectContext.CustomerOrders.Include(<span class="str">"OrderDetails"</span>);
        }

        <span class="kwrd">public</span> <span class="kwrd">void</span> InsertCustomerOrder(CustomerOrder customerOrder)
        {
            <span class="kwrd">if</span> ((customerOrder.EntityState != EntityState.Detached))
            {
                <span class="kwrd">this</span>.ObjectContext.ObjectStateManager.ChangeObjectState(customerOrder, EntityState.Added);
            }
            <span class="kwrd">else</span>
            {
                <span class="kwrd">this</span>.ObjectContext.CustomerOrders.AddObject(customerOrder);
            }

            UpdateAssociatedDetails(customerOrder);
        }

        <span class="kwrd">private</span> <span class="kwrd">void</span> UpdateAssociatedDetails(CustomerOrder customerOrder)
        {
            System.Collections.IEnumerable details =
                <span class="kwrd">this</span>.ChangeSet.GetAssociatedChanges&lt;CustomerOrder, EntityCollection&lt;OrderDetail&gt;&gt;
                    (customerOrder, o =&gt; o.OrderDetails);
            <span class="kwrd">foreach</span> (OrderDetail detail <span class="kwrd">in</span> details)
            {
                ChangeOperation op = <span class="kwrd">this</span>.ChangeSet.GetChangeOperation(detail);
                <span class="kwrd">switch</span> (op)
                {
                    <span class="kwrd">case</span> ChangeOperation.Insert:
                        <span class="kwrd">if</span> (detail.EntityState != EntityState.Added)
                        {
                            <span class="kwrd">if</span> (detail.EntityState != EntityState.Detached)
                            {
                                <span class="kwrd">this</span>.ObjectContext.ObjectStateManager.ChangeObjectState(detail, EntityState.Added);
                            }
                            <span class="kwrd">else</span>
                            {
                                <span class="kwrd">this</span>.ObjectContext.OrderDetails.AddObject(detail);
                            }
                        }
                        <span class="kwrd">break</span>;

                    <span class="kwrd">case</span> ChangeOperation.Update:
                        <span class="kwrd">if</span> (detail.EntityState == EntityState.Detached)
                        {
                            <span class="kwrd">this</span>.ObjectContext.Attach(detail);
                        }
                        <span class="kwrd">this</span>.ObjectContext.ObjectStateManager.ChangeObjectState(detail, EntityState.Modified);
                        <span class="kwrd">break</span>;

                    <span class="kwrd">case</span> ChangeOperation.Delete:
                        <span class="kwrd">if</span> (detail.EntityState == EntityState.Detached)
                        {
                            <span class="kwrd">this</span>.ObjectContext.OrderDetails.Attach(detail);
                        }
                        customerOrder.OrderDetails.Remove(detail);
                        <span class="kwrd">this</span>.ObjectContext.DeleteObject(detail);
                        <span class="kwrd">break</span>;

                    <span class="kwrd">case</span> ChangeOperation.None:

                        <span class="rem">// MSDN had omitted these</span>
                        <span class="kwrd">if</span> (detail.EntityState == EntityState.Added)
                            <span class="kwrd">this</span>.ObjectContext.ObjectStateManager.ChangeObjectState(detail, EntityState.Unchanged);
                        <span class="kwrd">break</span>;

                    <span class="kwrd">default</span>:
                        <span class="kwrd">break</span>;
                }

            }

            <span class="kwrd">double</span> totalPrice = customerOrder.OrderDetails.Sum(d =&gt; d.Price);
            customerOrder.TotalPrice = (<span class="kwrd">float</span>) totalPrice;
        }

        <span class="kwrd">public</span> <span class="kwrd">void</span> UpdateCustomerOrder(CustomerOrder currentCustomerOrder)
        {
            <span class="kwrd">try</span>
            {
                <span class="kwrd">if</span> (currentCustomerOrder.EntityState == EntityState.Detached)
                {

                    CustomerOrder originalOrder = <span class="kwrd">this</span>.ChangeSet.GetOriginal(currentCustomerOrder);
                    <span class="kwrd">if</span> (originalOrder != <span class="kwrd">null</span>)
                    {
                        <span class="kwrd">this</span>.ObjectContext.CustomerOrders.AttachAsModified(currentCustomerOrder, originalOrder);

                    }
                    <span class="kwrd">else</span>
                    {
                        <span class="rem">// http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/thread/a633a58e-85ad-4e77-be80-b1855bfd2b42</span>
                        <span class="kwrd">this</span>.ObjectContext.CustomerOrders.AddObject(currentCustomerOrder);
                        <span class="kwrd">this</span>.ObjectContext.ObjectStateManager.ChangeObjectState(currentCustomerOrder, EntityState.Unchanged);

                        <span class="rem">// MSDN is wrong.</span>
                        <span class="rem">// this.ObjectContext.CustomerOrders.Attach(currentCustomerOrder);</span>
                    }
                }

                UpdateAssociatedDetails(currentCustomerOrder);
            }
            <span class="kwrd">catch</span> (Exception exc)
            {
                <span class="kwrd">string</span> message = exc.Message;
                <span class="kwrd">throw</span>;
            }

        }

        <span class="kwrd">public</span> <span class="kwrd">void</span> DeleteCustomerOrder(CustomerOrder customerOrder)
        {
            <span class="kwrd">if</span> ((customerOrder.EntityState == EntityState.Detached))
            {
                <span class="kwrd">this</span>.ObjectContext.CustomerOrders.Attach(customerOrder);
            }
            <span class="kwrd">foreach</span> (var detail <span class="kwrd">in</span> customerOrder.OrderDetails.ToList())
                <span class="kwrd">this</span>.ObjectContext.DeleteObject(detail);
            <span class="kwrd">this</span>.ObjectContext.CustomerOrders.DeleteObject(customerOrder);
        }

    }

}
</pre>
<p>Formatting courtesy of <a href="http://www.manoli.net/csharpformat/">Code to HTML format</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/wcf-ria-services-composition/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing for overlapping/intersecting date ranges</title>
		<link>http://www.redmountainsw.com/wordpress/archives/overlapping-date-ranges</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/overlapping-date-ranges#comments</comments>
		<pubDate>Wed, 04 Aug 2010 00:16:07 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1013</guid>
		<description><![CDATA[How do we test whether one date range intersects/overlaps another date range?
There are six possible combinations to consider.

entire date range falls outside of our specified range (too early)
date partially falls partially inside our range (start date out of range)
date range encompasses our range entirely
date falls entirely inside our range
date partially falls inside our range (end [...]]]></description>
			<content:encoded><![CDATA[<p>How do we test whether one date range intersects/overlaps another date range?</p>
<p>There are six possible combinations to consider.</p>
<ol>
<li>entire date range falls outside of our specified range (too early)</li>
<li>date partially falls partially inside our range (start date out of range)</li>
<li>date range encompasses our range entirely</li>
<li>date falls entirely inside our range</li>
<li>date partially falls inside our range (end date out of range)</li>
<li>date falls outside our specified range (too late)</li>
</ol>
<p><a href="http://www.redmountainsw.com/wordpress/wp-content/uploads/daterange1.png"><img src="http://www.redmountainsw.com/wordpress/wp-content/uploads/daterange1.png" alt="" title="date range falls within another range" width="517" height="445" class="aligncenter size-full wp-image-1015" /></a></p>
<p>The hard way to do this is to handle cases 2, 3, 4 and 5 using an OR criteria, since each criteria requires two checks, this results in total of 8 tests.</p>
<p>The easy way is to handle cases 1 and 6, which only requires a single test for each.</p>
<pre class="brush: sql">
   Not (EndDate &lt; &#039;2010-01-15:00:00:00&#039; Or StartDate &gt; &#039;2010-03-15:00:00:00&#039;)
</pre>
<p>which can be simplified to</p>
<pre class="brush: sql">
   EndDate =&gt; &#039;2010-01-15:00:00:00&#039; And StartDate =&lt; &#039;2010-03-15:00:00:00&#039;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/overlapping-date-ranges/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
