<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:a10="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
	<channel>
		<title>SingingEels : Development Community &amp; Resource</title>
		<link>http://www.singingeels.com/</link>
		<description>SingingEels.com is a fresh and new article site dedicated to web programming in ASP.NET, general architecture, web and coding standards, SQL and security.</description>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/SingingEelsBlogs" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/Nullable/2009/06/04/When_Runtime_Errors_Become_Inappropriate.aspx</guid>
			<link>http://feedproxy.google.com/~r/SingingEelsBlogs/~3/vARUXBktQns/When_Runtime_Errors_Become_Inappropriate.aspx</link>
			<author>Timothy Khouri</author>
			<title>When Runtime Errors Become Inappropriate</title>
			<description>&lt;p&gt;So I got an email yesterday from the Microsoft Partner Program reminding me that it's time to re-enroll &lt;a href="http://www.beam4d.com/" rel="nofollow"&gt;BEAM 4D&lt;/a&gt; (the company that I work for). The email was friendly, as usual, and even provided a direct link for me to get right to the re-enrollment process.&lt;/p&gt;

&lt;p&gt;Seeing as I was given the task to get the company certified in the program, I took it upon myself to click the link and fill out the form. What I found on the other side of the link surprised me a little.&lt;/p&gt;

&lt;img src="./Articles/UserImage.aspx?ImageID=7a2a0908-cf3e-4fcb-bba0-683d00d0dcae" alt="ASP.NET Runtime Error on Microsoft's Partner Website" title="ASP.NET Runtime Error on Microsoft's Partner Website" /&gt;

&lt;p&gt;Now don't get me wrong - runtime errors are not uncommon, and I don't think *anyone* is impervious to them. So I figured I'd wait a day and check back. Surely MS has been alerted of this error (as I refreshed several times) and by now they have diagnosed the problem and fixed it!... well, I'm still getting the error!&lt;/p&gt;

&lt;p&gt;This lead me to posting this quick blog snippet. Since ASP.NET makes it very easy to put up a friendly looking "oops, we got an error" page... and since Microsoft developed ASP.NET... and since the MS Partner Program is all about associating yourself with highly skilled professionals... ... ... shouldn't I *not* be seeing the standard "hey, this is my first ASP.NET site" error message?&lt;/p&gt;

&lt;p&gt;Well, at least the customErrors tag isn't set to "Off" (although it would be fun to see what the error is).&lt;/p&gt;

&lt;h3&gt;DISCLAIMER and ALL-FAIRNESS-CLAUSE
&lt;/h3&gt;&lt;p&gt;In all fairness, I've seen error messages on lots of large corporations sites. And to be even more fair, not every site/product associated with Microsoft is going to be the most dominant thing in the world.&lt;/p&gt;

&lt;p&gt;I love Microsoft probably more than the normal fanboy, but it's always fun to screen shot these events and log them in memory (aka, a random blog on the internet).&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/vARUXBktQns" height="1" width="1"/&gt;</description>
			<pubDate>Thu, 04 Jun 2009 05:44:59 -0600</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/Nullable/2009/06/04/When_Runtime_Errors_Become_Inappropriate.aspx</feedburner:origLink></item>
		<item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/sycho/2009/05/11/Problem_with_self_sorting_gridview.aspx</guid>
			<link>http://feedproxy.google.com/~r/SingingEelsBlogs/~3/v7ScCniGD7E/Problem_with_self_sorting_gridview.aspx</link>
			<author>sycho</author>
			<category>LINQ</category>
			<title>Problem with self sorting gridview</title>
			<description>&lt;p&gt;Hi&lt;/p&gt;

&lt;p&gt;Thanks for this great class. I was searching for this for a long time and I couldn't get it to work in my program. Now it works but it has one problem in my program.&lt;/p&gt;

&lt;h3&gt;The code below works just fine:
&lt;/h3&gt;&lt;p&gt;List &amp;lt;vIntStudent&amp;gt; student = BLStudent.GetAllStudents();&lt;/p&gt;

&lt;h3&gt;Gridview.datasource = student;
&lt;/h3&gt;&lt;p&gt;Gridview.databind();&lt;/p&gt;

&lt;p&gt;This shows me all the information in my students table.&lt;/p&gt;

&lt;h3&gt;But I want to not have all the information in my table. So I do in the gridview on the aspx page:
&lt;/h3&gt;&lt;h3&gt;&amp;lt;singleEels:selfsortinggridview id="GridView1" runat="server" allowsorting="true"&amp;gt;
&lt;/h3&gt;&lt;h3&gt;  &amp;lt;columns&amp;gt;
&lt;/h3&gt;&lt;h3&gt;    &amp;lt;asp:boundfield headertext="test" datafield="fieldInTable" sortexpressioin="fieldInTable" /&amp;gt;
&lt;/h3&gt;&lt;h3&gt;  &amp;lt;/columns&amp;gt;
&lt;/h3&gt;&lt;p&gt;&amp;lt;/singleEels:selfsortinggridview&amp;gt;&lt;/p&gt;

&lt;p&gt;This gives me an 'object reference not set to an instance of an object' error. I've debugged the selfsortinggridview class and everything is filled in correctly but when I come in the LateBoundSorter class it gives the above error. There is going something wrong in the GetPropertyValue.&lt;/p&gt;

&lt;p&gt;Can somebody help me with this?&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/v7ScCniGD7E" height="1" width="1"/&gt;</description>
			<pubDate>Mon, 11 May 2009 00:59:35 -0600</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/sycho/2009/05/11/Problem_with_self_sorting_gridview.aspx</feedburner:origLink></item>
		<item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/kiwipete/2009/03/25/Follow_up_to_Self_Sorting_GridView.aspx</guid>
			<link>http://feedproxy.google.com/~r/SingingEelsBlogs/~3/3PPnALRVKnA/Follow_up_to_Self_Sorting_GridView.aspx</link>
			<author>kiwipete</author>
			<category>ASP.NET</category>
			<category>LINQ</category>
			<title>Follow up to Self Sorting GridView</title>
			<description>&lt;h3&gt;Some updates I made to
&lt;/h3&gt;&lt;h3&gt;http://www.singingeels.com/Articles/Self_Sorting_GridView_with_LINQ_Expression_Trees.aspx
&lt;/h3&gt;&lt;p&gt;to allow Self Paging as well as sorting.&lt;/p&gt;

&lt;h3&gt;using System;
&lt;/h3&gt;&lt;h3&gt;using System.Collections;
&lt;/h3&gt;&lt;h3&gt;using System.Collections.Generic;
&lt;/h3&gt;&lt;h3&gt;using System.Linq;
&lt;/h3&gt;&lt;h3&gt;using System.Linq.Expressions;
&lt;/h3&gt;&lt;h3&gt;using System.Reflection;
&lt;/h3&gt;&lt;h3&gt;using System.Web.UI;
&lt;/h3&gt;&lt;p&gt;using System.Web.UI.WebControls;&lt;/p&gt;

&lt;h3&gt;namespace SingingEels.Web.UI.WebControls
&lt;/h3&gt;&lt;h3&gt;{
&lt;/h3&gt;&lt;h3&gt;    // SelfSortingGridView - GridView from www.singingeels.com
&lt;/h3&gt;&lt;h3&gt;    // Updated to allow paging as well as sorting.
&lt;/h3&gt;&lt;h3&gt;    public class LinqGridView : GridView
&lt;/h3&gt;&lt;h3&gt;	{
&lt;/h3&gt;&lt;h3&gt;		private string _lastSortExpression;
&lt;/h3&gt;&lt;p&gt;        private SortDirection _lastSortDirection;&lt;/p&gt;

&lt;h3&gt;		protected override void OnSorting(GridViewSortEventArgs e)
&lt;/h3&gt;&lt;h3&gt;		{
&lt;/h3&gt;&lt;h3&gt;			this.Sorting += new GridViewSortEventHandler(this.SelfSortingGridView_Sorting);
&lt;/h3&gt;&lt;h3&gt;			base.OnSorting(e);
&lt;/h3&gt;&lt;p&gt;		}&lt;/p&gt;

&lt;h3&gt;		private void SelfSortingGridView_Sorting(object sender, GridViewSortEventArgs e)
&lt;/h3&gt;&lt;h3&gt;		{
&lt;/h3&gt;&lt;p&gt;            this.PageIndex = 0; // Go back to the start of the list on sorting.&lt;/p&gt;

&lt;h3&gt;            if (e.SortExpression == this._lastSortExpression &amp;amp;&amp;amp; this._lastSortDirection == SortDirection.Ascending)
&lt;/h3&gt;&lt;h3&gt;            {
&lt;/h3&gt;&lt;h3&gt;                e.SortDirection = SortDirection.Descending;
&lt;/h3&gt;&lt;h3&gt;            }
&lt;/h3&gt;&lt;h3&gt;            else
&lt;/h3&gt;&lt;h3&gt;            {
&lt;/h3&gt;&lt;h3&gt;                e.SortDirection = SortDirection.Ascending;
&lt;/h3&gt;&lt;h3&gt;            }
&lt;/h3&gt;&lt;h3&gt;            SetupSorting(e.SortExpression, e.SortDirection);
&lt;/h3&gt;&lt;h3&gt;            this.DataBind();
&lt;/h3&gt;
&lt;h3&gt;            this._lastSortExpression = e.SortExpression;
&lt;/h3&gt;&lt;h3&gt;            this._lastSortDirection = e.SortDirection;
&lt;/h3&gt;&lt;p&gt;        }&lt;/p&gt;

&lt;h3&gt;        protected override void OnPageIndexChanging(GridViewPageEventArgs eArgs)
&lt;/h3&gt;&lt;h3&gt;        {
&lt;/h3&gt;&lt;h3&gt;            this.PageIndexChanging += new GridViewPageEventHandler(this.SelfSortingGridView_PageIndexChanging);
&lt;/h3&gt;&lt;h3&gt;            base.OnPageIndexChanging(eArgs);
&lt;/h3&gt;&lt;p&gt;        }&lt;/p&gt;

&lt;h3&gt;        private void SelfSortingGridView_PageIndexChanging(object sender, GridViewPageEventArgs eArgs)
&lt;/h3&gt;&lt;h3&gt;        {
&lt;/h3&gt;&lt;h3&gt;            this.PageIndex = eArgs.NewPageIndex;
&lt;/h3&gt;&lt;h3&gt;            if (!string.IsNullOrEmpty(this._lastSortExpression))
&lt;/h3&gt;&lt;h3&gt;                SetupSorting(this._lastSortExpression, this._lastSortDirection);
&lt;/h3&gt;&lt;h3&gt;            this.DataBind();
&lt;/h3&gt;&lt;p&gt;        }&lt;/p&gt;

&lt;h3&gt;        private void SetupSorting(string sortExpression, SortDirection sortDirection)
&lt;/h3&gt;&lt;h3&gt;        {
&lt;/h3&gt;&lt;p&gt;			IEnumerable _data = null;&lt;/p&gt;

&lt;h3&gt;			// This will allow LINQ to SQL to pass the sorting on to the SQL Server itself.
&lt;/h3&gt;&lt;h3&gt;			if (this.DataSource is IQueryable)
&lt;/h3&gt;&lt;h3&gt;			{
&lt;/h3&gt;&lt;h3&gt;				_data = (IQueryable)this.DataSource;
&lt;/h3&gt;&lt;h3&gt;			}
&lt;/h3&gt;&lt;h3&gt;			else
&lt;/h3&gt;&lt;h3&gt;			{
&lt;/h3&gt;&lt;p&gt;				DataSourceView dataView = this.GetData();&lt;/p&gt;

&lt;h3&gt;				if (dataView == null)
&lt;/h3&gt;&lt;h3&gt;				{
&lt;/h3&gt;&lt;h3&gt;					// No data to sort.
&lt;/h3&gt;&lt;h3&gt;					return;
&lt;/h3&gt;&lt;p&gt;				}&lt;/p&gt;

&lt;h3&gt;				dataView.Select(this.SelectArguments, delegate(IEnumerable data)
&lt;/h3&gt;&lt;h3&gt;				{
&lt;/h3&gt;&lt;h3&gt;					_data = data;
&lt;/h3&gt;&lt;p&gt;				});&lt;/p&gt;

&lt;h3&gt;				if (_data == null)
&lt;/h3&gt;&lt;h3&gt;				{
&lt;/h3&gt;&lt;h3&gt;					// No data to sort.
&lt;/h3&gt;&lt;h3&gt;					return;
&lt;/h3&gt;&lt;h3&gt;				}
&lt;/h3&gt;&lt;p&gt;			}&lt;/p&gt;

&lt;p&gt;			Type dataSourceType = _data.GetType();&lt;/p&gt;

&lt;p&gt;			Type dataItemType = typeof(object);&lt;/p&gt;

&lt;h3&gt;			if (dataSourceType.HasElementType)
&lt;/h3&gt;&lt;h3&gt;			{
&lt;/h3&gt;&lt;h3&gt;				dataItemType = dataSourceType.GetElementType();
&lt;/h3&gt;&lt;h3&gt;			}
&lt;/h3&gt;&lt;h3&gt;			else if (dataSourceType.IsGenericType)
&lt;/h3&gt;&lt;h3&gt;			{
&lt;/h3&gt;&lt;h3&gt;				dataItemType = dataSourceType.GetGenericArguments()[0];
&lt;/h3&gt;&lt;h3&gt;			}
&lt;/h3&gt;&lt;h3&gt;			else if (_data is IEnumerable)
&lt;/h3&gt;&lt;h3&gt;			{
&lt;/h3&gt;&lt;p&gt;				IEnumerator dataEnumerator = _data.GetEnumerator();&lt;/p&gt;

&lt;h3&gt;				if (dataEnumerator.MoveNext() &amp;amp;&amp;amp; dataEnumerator.Current != null)
&lt;/h3&gt;&lt;h3&gt;				{
&lt;/h3&gt;&lt;h3&gt;					dataItemType = dataEnumerator.Current.GetType();
&lt;/h3&gt;&lt;h3&gt;				}
&lt;/h3&gt;&lt;p&gt;			}&lt;/p&gt;

&lt;p&gt;			var fieldType = dataItemType.GetProperty(sortExpression);&lt;/p&gt;

&lt;p&gt;			object sorterObject = null;&lt;/p&gt;

&lt;p&gt;			Type sorterType = null;&lt;/p&gt;

&lt;h3&gt;			// We'll handle things like LINQ to SQL differently by passing the love
&lt;/h3&gt;&lt;h3&gt;			// on to the provider.
&lt;/h3&gt;&lt;p&gt;			PropertyInfo property = dataItemType.GetProperty(sortExpression);&lt;/p&gt;

&lt;h3&gt;			if (property != null)
&lt;/h3&gt;&lt;h3&gt;			{
&lt;/h3&gt;&lt;p&gt;				sorterType = typeof(GenericSorter&amp;lt;,&amp;gt;).MakeGenericType(dataItemType, property.PropertyType);&lt;/p&gt;

&lt;h3&gt;				sorterObject = Activator.CreateInstance(sorterType);
&lt;/h3&gt;&lt;h3&gt;			}
&lt;/h3&gt;&lt;h3&gt;			else
&lt;/h3&gt;&lt;h3&gt;			{
&lt;/h3&gt;&lt;p&gt;				sorterType = typeof(LateBoundSorter);&lt;/p&gt;

&lt;h3&gt;				sorterObject = Activator.CreateInstance(sorterType);
&lt;/h3&gt;&lt;p&gt;			}&lt;/p&gt;

&lt;h3&gt;			this.DataSource = sorterType.GetMethod("Sort", new Type[] { dataSourceType, typeof(string), typeof(SortDirection) })
&lt;/h3&gt;&lt;p&gt;				.Invoke(sorterObject, new object[] { _data, sortExpression, sortDirection });&lt;/p&gt;

&lt;p&gt;		}&lt;/p&gt;

&lt;h3&gt;		protected override object SaveControlState()
&lt;/h3&gt;&lt;h3&gt;		{
&lt;/h3&gt;&lt;h3&gt;			return new object[] { this._lastSortExpression, this._lastSortDirection, base.SaveControlState() };
&lt;/h3&gt;&lt;p&gt;		}&lt;/p&gt;

&lt;h3&gt;		protected override void LoadControlState(object savedState)
&lt;/h3&gt;&lt;h3&gt;		{
&lt;/h3&gt;&lt;p&gt;			object[] stateItems = savedState as object[];&lt;/p&gt;

&lt;h3&gt;			if (stateItems != null &amp;amp;&amp;amp; stateItems.Length == 3)
&lt;/h3&gt;&lt;h3&gt;			{
&lt;/h3&gt;&lt;h3&gt;				this._lastSortExpression = (String) stateItems[0];
&lt;/h3&gt;&lt;p&gt;                this._lastSortDirection = (SortDirection) stateItems[1];&lt;/p&gt;

&lt;h3&gt;				base.LoadControlState(stateItems[2]);
&lt;/h3&gt;&lt;h3&gt;			}
&lt;/h3&gt;&lt;h3&gt;			else
&lt;/h3&gt;&lt;h3&gt;			{
&lt;/h3&gt;&lt;h3&gt;				base.LoadControlState(savedState);
&lt;/h3&gt;&lt;h3&gt;			}
&lt;/h3&gt;&lt;h3&gt;		}
&lt;/h3&gt;&lt;p&gt;	}&lt;/p&gt;

&lt;h3&gt;	public class GenericSorter&amp;lt;T, PT&amp;gt;
&lt;/h3&gt;&lt;h3&gt;	{
&lt;/h3&gt;&lt;h3&gt;		public IEnumerable&amp;lt;T&amp;gt; Sort(IEnumerable source, string sortExpression, SortDirection sortDirection)
&lt;/h3&gt;&lt;h3&gt;		{
&lt;/h3&gt;&lt;p&gt;			var param = Expression.Parameter(typeof(T), "item");&lt;/p&gt;

&lt;p&gt;			var sortLambda = Expression.Lambda&amp;lt;Func&amp;lt;T, PT&amp;gt;&amp;gt;(Expression.Convert(Expression.Property(param, sortExpression), typeof(PT)), param);&lt;/p&gt;

&lt;h3&gt;			if (sortDirection == SortDirection.Ascending)
&lt;/h3&gt;&lt;h3&gt;			{
&lt;/h3&gt;&lt;h3&gt;				return source.OfType&amp;lt;T&amp;gt;().AsQueryable&amp;lt;T&amp;gt;().OrderBy&amp;lt;T, PT&amp;gt;(sortLambda);
&lt;/h3&gt;&lt;h3&gt;			}
&lt;/h3&gt;&lt;h3&gt;			else
&lt;/h3&gt;&lt;h3&gt;			{
&lt;/h3&gt;&lt;h3&gt;				return source.OfType&amp;lt;T&amp;gt;().AsQueryable&amp;lt;T&amp;gt;().OrderByDescending&amp;lt;T, PT&amp;gt;(sortLambda);
&lt;/h3&gt;&lt;h3&gt;			}
&lt;/h3&gt;&lt;p&gt;		}&lt;/p&gt;

&lt;h3&gt;		public IEnumerable&amp;lt;T&amp;gt; Sort(IEnumerable&amp;lt;T&amp;gt; source, string sortExpression, SortDirection sortDirection)
&lt;/h3&gt;&lt;h3&gt;		{
&lt;/h3&gt;&lt;p&gt;			var param = Expression.Parameter(typeof(T), "item");&lt;/p&gt;

&lt;p&gt;			var sortLambda = Expression.Lambda&amp;lt;Func&amp;lt;T, PT&amp;gt;&amp;gt;(Expression.Convert(Expression.Property(param, sortExpression), typeof(PT)), param);&lt;/p&gt;

&lt;h3&gt;			if (sortDirection == SortDirection.Ascending)
&lt;/h3&gt;&lt;h3&gt;			{
&lt;/h3&gt;&lt;h3&gt;				return source.AsQueryable&amp;lt;T&amp;gt;().OrderBy&amp;lt;T, PT&amp;gt;(sortLambda);
&lt;/h3&gt;&lt;h3&gt;			}
&lt;/h3&gt;&lt;h3&gt;			else
&lt;/h3&gt;&lt;h3&gt;			{
&lt;/h3&gt;&lt;h3&gt;				return source.AsQueryable&amp;lt;T&amp;gt;().OrderByDescending&amp;lt;T, PT&amp;gt;(sortLambda);
&lt;/h3&gt;&lt;h3&gt;			}
&lt;/h3&gt;&lt;h3&gt;		}
&lt;/h3&gt;&lt;p&gt;	}&lt;/p&gt;

&lt;h3&gt;	public class LateBoundSorter
&lt;/h3&gt;&lt;h3&gt;	{
&lt;/h3&gt;&lt;h3&gt;		public IEnumerable Sort(IEnumerable source, string sortExpression, SortDirection sortDirection)
&lt;/h3&gt;&lt;h3&gt;		{
&lt;/h3&gt;&lt;h3&gt;			if (sortDirection == SortDirection.Ascending)
&lt;/h3&gt;&lt;h3&gt;			{
&lt;/h3&gt;&lt;h3&gt;				return source.OfType&amp;lt;object&amp;gt;().OrderBy(item =&amp;gt;
&lt;/h3&gt;&lt;h3&gt;					this.GetPropertyValue(item, sortExpression));
&lt;/h3&gt;&lt;h3&gt;			}
&lt;/h3&gt;&lt;h3&gt;			else
&lt;/h3&gt;&lt;h3&gt;			{
&lt;/h3&gt;&lt;h3&gt;                return source.OfType&amp;lt;object&amp;gt;().OrderByDescending(item =&amp;gt;
&lt;/h3&gt;&lt;h3&gt;					this.GetPropertyValue(item, sortExpression));
&lt;/h3&gt;&lt;h3&gt;			}
&lt;/h3&gt;&lt;p&gt;		}&lt;/p&gt;

&lt;h3&gt;		private object GetPropertyValue(object item, string propertyName)
&lt;/h3&gt;&lt;h3&gt;		{
&lt;/h3&gt;&lt;h3&gt;			return item.GetType().GetProperty(propertyName).GetValue(item, null);
&lt;/h3&gt;&lt;h3&gt;		}
&lt;/h3&gt;&lt;h3&gt;	}
&lt;/h3&gt;&lt;p&gt;}&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/3PPnALRVKnA" height="1" width="1"/&gt;</description>
			<pubDate>Wed, 25 Mar 2009 17:16:29 -0600</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/kiwipete/2009/03/25/Follow_up_to_Self_Sorting_GridView.aspx</feedburner:origLink></item>
		<item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/Nullable/2009/01/09/How_to_Make_LINQ_to_SQL_Check_for_Changes_After_Attach_or_AttachAll.aspx</guid>
			<link>http://feedproxy.google.com/~r/SingingEelsBlogs/~3/bRCIfp2h0d4/How_to_Make_LINQ_to_SQL_Check_for_Changes_After_Attach_or_AttachAll.aspx</link>
			<author>Timothy Khouri</author>
			<category>LINQ</category>
			<title>How to Make LINQ to SQL Check for Changes After Attach (or AttachAll)</title>
			<description>&lt;p&gt;For the past hour or so, I've been struggling with something that I thought would be very easy for LINQ to SQL to handle on it's own - that is - performing an "IsDirty" check of sorts. It turns out the solution *is* easy, but it's just not what I was thinking to do at first.&lt;/p&gt;

&lt;p&gt;Here's the scenario: The application I'm working on is a semi-disconnected client/server system. What I mean by that is, the client (WPF application) will connect to the server (using WCF) to download some records. The client can edit and add items to the list, and then when they want to save, it sends the complete list back up to the server (to either update, or add the items).&lt;/p&gt;

&lt;p&gt;Well, since some of the items were already in the database, I can't just call "InsertAllOnSubmit", because LINQ will yell at me for trying to insert duplicate items.&lt;/p&gt;

&lt;p&gt;Also, since some of the items may not already be in the database, I can't just call "AttachAll", because then LINQ will yell at me again for 'adding the same key twice'.&lt;/p&gt;

&lt;div class="note"&gt;&lt;p&gt;Note: The "same key" being used is actually the ID "0". The reason for this is that the "ID" field will be auto-generated by the server. So, if you try to attach two or more entities that are new (therefore have ID 0), then it seems that you are creating a duplicate entry.&lt;/p&gt;&lt;/div&gt;

&lt;h3&gt;How to "add or update" entities in LINQ to SQL
&lt;/h3&gt;&lt;p&gt;The solution here was pretty simple. All items in the list that have an ID need to be 'attached', and all items that don't have an ID need to be 'inserted'. So, here's what my code looks like:&lt;/p&gt;

&lt;div class="CodeBlock c#"&gt;&lt;span class="KeyWord"&gt;public&lt;/span&gt; &lt;span class="KeyWord"&gt;void&lt;/span&gt; SaveUserSettings(UserSetting[] settings)&lt;br /&gt;
{&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;&lt;span class="KeyWord"&gt;using&lt;/span&gt; (&lt;span class="KeyWord"&gt;var&lt;/span&gt; dataContext = &lt;span class="KeyWord"&gt;new&lt;/span&gt; MyDataContext())&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;{&lt;span class="Comment"&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Update all existing entries.&lt;/span&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dataContext.UserSettings.AttachAll(settings.Where(item =&amp;gt; item.ID != 0));&lt;span class="Comment"&gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Add any &lt;span class="KeyWord"&gt;new&lt;/span&gt; entries.&lt;/span&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dataContext.UserSettings.InsertAllOnSubmit(settings.Where(item =&amp;gt; item.ID == 0));&lt;br /&gt;
&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dataContext.SubmitChanges();&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
}&lt;/div&gt;

&lt;p&gt;This seemed to work great - new items were being added! But, there is a problem with the above code: existing items weren't being updated. "Why?" you might ask. The answer (now that I understand it better) is simple:&lt;/p&gt;

&lt;p&gt;LINQ to SQL assumes that the object you are attaching is un-modified. True, there is an overloaded method "AttachAll(items, true)" that forces LINQ to view those objects as 'modified', but that method only works if your table has a TimeStamp field.&lt;/p&gt;

&lt;div class="note"&gt;&lt;p&gt;The error message that you'll get if you try to use the above overload is: "An entity can only be attached as modified without original state if it declares a version member or does not have an update check policy." - You can set every field to check for updates "Never", but then you lose the ability to know if another user has change the database in the mean time.&lt;/p&gt;&lt;/div&gt;

&lt;p&gt;So, how do I tell LINQ to SQL to see if there have been changes made to already-existing entities? By using the "Refresh" method:&lt;/p&gt;

&lt;div class="CodeBlock c#"&gt;&lt;span class="Comment"&gt;// Add &lt;span class="KeyWord"&gt;this&lt;/span&gt; line before &lt;span class="String"&gt;"SubmitChanges"&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
dataContext.Refresh(RefreshMode.KeepCurrentValues, settings);&lt;/div&gt;

&lt;p&gt;That's it! Now I am explicitly telling LINQ to SQL to check if there were any updates to those objects and to keep the new values. As a result, the DataContext is now aware of any changes, and will update them accordingly when "SubmitChanges" is called.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/bRCIfp2h0d4" height="1" width="1"/&gt;</description>
			<pubDate>Fri, 09 Jan 2009 09:04:49 -0700</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/Nullable/2009/01/09/How_to_Make_LINQ_to_SQL_Check_for_Changes_After_Attach_or_AttachAll.aspx</feedburner:origLink></item>
		<item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/Nullable/2008/11/06/WPF_Bug__assembly_used_when_compiling_might_be_different.aspx</guid>
			<link>http://feedproxy.google.com/~r/SingingEelsBlogs/~3/Cv9HNYrsaV8/WPF_Bug__assembly_used_when_compiling_might_be_different.aspx</link>
			<author>Timothy Khouri</author>
			<title>WPF Bug : "assembly used when compiling might be different"</title>
			<description>&lt;p&gt;Recently, we made the switch at my job to use WPF for our Windows apps (and even for new User Controls in existing apps). I'm absolutely loving WPF, and all of it's goodness. There have been a few learning curves, but all in all it's been worth it.&lt;/p&gt;

&lt;p&gt;Yesterday, however, I found my first "stupid bug" in WPF. A "stupid bug" is a bug that doesn't even begin to make sense. I've already seen a &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/fa89b481-9f7a-4f06-a8d4-290fc97fa168/" rel="nofollow"&gt;bug&lt;/a&gt; that was simply the mistake of the developer at Microsoft who made the 'GroupBox' control. (Thanks "&lt;a href="http://drwpf.com/blog/" rel="nofollow"&gt;Dr. WPF&lt;/a&gt;" for figuring that one out and fixing it.)&lt;/p&gt;

&lt;p&gt;But &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6f2fc9e3-bd1f-4626-881a-3af3fb8c062a/" rel="nofollow"&gt;this bug&lt;/a&gt; is beyond me as to why it happens. I can't even begin to understand who to blame on the WPF team for this one :)&lt;/p&gt;

&lt;h3&gt;How to Recreate the Bug
&lt;/h3&gt;&lt;p&gt;To see this bug for yourself doesn't take much. I simply downloaded the WPFToolkit from CodePlex, and tried to use the DatePicker. After referencing the DLL, everything looks great in the designer (and in the XAML). But, if I run my app, I get this error:&lt;/p&gt;

&lt;img src="./Articles/UserImage.aspx?ImageID=2f4df375-d025-4ab3-a796-249bf1f9af4f" alt="Runtime error caused by using a WPF control from another DLL without specifying a name" title="Runtime error caused by using a WPF control from another DLL without specifying a name" /&gt;

&lt;p&gt;What's the problem you might ask? Quite stupidly... you'll get this error if you don't have a "Name" property on your control.&lt;/p&gt;

&lt;p&gt;That's it! From what I've seen, if you add a reference to an assembly that has WPF controls in it... you can use those controls, but if you don't give them a Name, then at runtime, you'll get an error.&lt;/p&gt;

&lt;p&gt;Horribly stupid bug... but, it is a very simple fix (just add a name)!&lt;/p&gt;

&lt;h3&gt;Show Me The XAML!
&lt;/h3&gt;&lt;p&gt;Here's the XAML that will error at runtime:&lt;/p&gt;

&lt;div class="CodeBlock xml"&gt;&amp;lt;&lt;span class="Tag"&gt;my:DatePicker&lt;/span&gt; /&amp;gt;&lt;/div&gt;

&lt;p&gt;Here's the XAML that will not error at runtime:&lt;/p&gt;

&lt;div class="CodeBlock xml"&gt;&amp;lt;&lt;span class="Tag"&gt;my:DatePicker&lt;/span&gt; &lt;span class="Key"&gt;Name&lt;/span&gt;&lt;span class="Value"&gt;="blahblah"&lt;/span&gt; /&amp;gt;&lt;/div&gt;

&lt;div class="note"&gt;&lt;p&gt;By the way, to add to the stupidity of this bug, you only have to name *one* of your DatePicker controls. So, if you have two on the same XAML page, you only have to name one of them and you won't get the error.&lt;/p&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/Cv9HNYrsaV8" height="1" width="1"/&gt;</description>
			<pubDate>Thu, 06 Nov 2008 08:46:20 -0700</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/Nullable/2008/11/06/WPF_Bug__assembly_used_when_compiling_might_be_different.aspx</feedburner:origLink></item>
		<item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/Nullable/2008/10/27/EntityFramework_Include_Equivalent_in_LINQ_to_SQL.aspx</guid>
			<link>http://feedproxy.google.com/~r/SingingEelsBlogs/~3/Qc0VAPJ5TZc/EntityFramework_Include_Equivalent_in_LINQ_to_SQL.aspx</link>
			<author>Timothy Khouri</author>
			<category>LINQ</category>
			<title>EntityFramework "Include" Equivalent in LINQ to SQL</title>
			<description>&lt;p&gt;Recently at my job, we switched from using DataSets over Web Services to using the EntityFramework over WCF. Within about two days, we switched off of using EF, and went to LINQ to SQL (which is my love really). The point of this post is not to put down EF, but is rather to show how to achieve one of the pieces of functionality in there that I liked... but with LINQ to SQL instead.&lt;/p&gt;

&lt;h3&gt;EntityFramework's "Include" Method
&lt;/h3&gt;&lt;p&gt;Because the &lt;a href="http://www.singingeels.com/Articles/Entity_Framework_and_Lazy_Loading.aspx" rel="nofollow"&gt;EntityFramework doesn't support lazy loading&lt;/a&gt;, you have to use the "Include" method to retrieve related data in your query. What I mean by this is that if you have a table called "Customers", and a table called "Orders" (which are linked together), this query will not populate the "Orders" data:&lt;/p&gt;

&lt;div class="CodeBlock c#"&gt;&lt;span class="Comment"&gt;// Using the Entity Framework&lt;/span&gt;&lt;br /&gt;
MyEntities context = &lt;span class="KeyWord"&gt;new&lt;/span&gt; MyEntities();&lt;br /&gt;
&lt;br /&gt;
&lt;span class="KeyWord"&gt;var&lt;/span&gt; orders = context.Customers&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;.First().Orders;&lt;/div&gt;

&lt;p&gt;but this code will:&lt;/p&gt;

&lt;div class="CodeBlock c#"&gt;&lt;span class="Comment"&gt;// Using the Entity Framework&lt;/span&gt;&lt;br /&gt;
MyEntities context = &lt;span class="KeyWord"&gt;new&lt;/span&gt; MyEntities();&lt;br /&gt;
&lt;br /&gt;
&lt;span class="KeyWord"&gt;var&lt;/span&gt; orders = context.Customers&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;.Include(&lt;span class="String"&gt;"Orders"&lt;/span&gt;)&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;.First().Orders;&lt;/div&gt;

&lt;p&gt;This is not new information, but what was new to me is that LINQ to SQL also supports this type of functionality (plus the implementation is better in my opinion).&lt;/p&gt;

&lt;h3&gt;EF's "Include" Equivalent in LINQ to SQL
&lt;/h3&gt;&lt;p&gt;You may be wondering, "Since LINQ to SQL supports lazy loading, why would you want to pre-download related data?" And the answer is quite simple: performance and distribution. If you know for a fact that you are going to use the "Orders" data when you pull your customer object, then it's much faster to hit SQL only once and download all the data, then loop through it in memory.&lt;/p&gt;

&lt;p&gt;Also (as is in my case), if you are planning on sending the object over a WCF connection (or a typical web-service), then you'll need to have all of the data in the object graph before sending it. Once the object is sent to the client, that's it!&lt;/p&gt;

&lt;p&gt;So, how do we achieve the same '.Include("Orders")' functionality? Here's the code:&lt;/p&gt;

&lt;div class="CodeBlock c#"&gt;&lt;span class="Comment"&gt;// Using L2S&lt;/span&gt;&lt;br /&gt;
MyDataContext context = &lt;span class="KeyWord"&gt;new&lt;/span&gt; MyDataContext();&lt;span class="Comment"&gt;&lt;br /&gt;
&lt;br /&gt;
// Create &lt;span class="String"&gt;"options"&lt;/span&gt; &lt;span class="KeyWord"&gt;for&lt;/span&gt; &lt;span class="KeyWord"&gt;this&lt;/span&gt; L2S context.&lt;/span&gt;&lt;br /&gt;
DataLoadOptions options = &lt;span class="KeyWord"&gt;new&lt;/span&gt; DataLoadOptions();&lt;span class="Comment"&gt;&lt;br /&gt;
&lt;br /&gt;
// Tell the options that we plan &lt;span class="KeyWord"&gt;on&lt;/span&gt; &lt;span class="KeyWord"&gt;using&lt;/span&gt; the Orders.&lt;/span&gt;&lt;br /&gt;
options.LoadWith&amp;lt;Customer&amp;gt;(item =&amp;gt; item.Orders);&lt;span class="Comment"&gt;&lt;br /&gt;
&lt;br /&gt;
// Set the options &lt;span class="KeyWord"&gt;on&lt;/span&gt; the context.&lt;/span&gt;&lt;br /&gt;
context.LoadOptions = options;&lt;span class="Comment"&gt;&lt;br /&gt;
&lt;br /&gt;
// There we go!&lt;/span&gt;&lt;br /&gt;
&lt;span class="KeyWord"&gt;var&lt;/span&gt; orders = context.Customers&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;.First().Orders;&lt;/div&gt;

&lt;div class="note"&gt;&lt;p&gt;You have to set your "LoadWith" options *before* you assign the "LoadOptions" property on the context. If you assign the property first, and then call "LoadWith", you'll get the following error: "LoadWith is not allowed after freeze or attach to DataContext."&lt;/p&gt;&lt;/div&gt;

&lt;h3&gt;Conclusion
&lt;/h3&gt;&lt;p&gt;So to wrap up this short blog post in an even shorter few sentenses, I'll conclude by saying the following: The EntityFramework doesn't support lazy loading. Instead, you have to specifically load relational properties with the "Include" method. LINQ to SQL does support deferred loading, but you can choose to load relational properties at the same time using the "LoadWith" method.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/Qc0VAPJ5TZc" height="1" width="1"/&gt;</description>
			<pubDate>Mon, 27 Oct 2008 19:19:52 -0600</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/Nullable/2008/10/27/EntityFramework_Include_Equivalent_in_LINQ_to_SQL.aspx</feedburner:origLink></item>
		<item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/Nullable/2008/10/01/Plans_to_the_Death_Star_Or_an_AutoGenerated_EDM.aspx</guid>
			<link>http://feedproxy.google.com/~r/SingingEelsBlogs/~3/skLWqE4dFw8/Plans_to_the_Death_Star_Or_an_AutoGenerated_EDM.aspx</link>
			<author>Timothy Khouri</author>
			<category>LINQ</category>
			<category>ADO.NET</category>
			<title>Plans to the Death Star... Or an Auto-Generated EDM?</title>
			<description>&lt;p&gt;I figured I have to post this really quickly... I just used the Entity Framework wizard to generate an EDM for the company I currently work for. For now, we're just doing a 1-to-1 of the database... (205 tables, 655 stored procedures, 2 views and 40 functions).&lt;/p&gt;

&lt;p&gt;The generated designer file (in C#) is 52,670 lines... yikes.&lt;/p&gt;

&lt;img src="./Articles/UserImage.aspx?ImageID=61686f8f-d889-4c96-a49d-4bbcd1e63466" alt="Auto Generated EDM for Large Database" title="Auto Generated EDM for Large Database" /&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/skLWqE4dFw8" height="1" width="1"/&gt;</description>
			<pubDate>Wed, 01 Oct 2008 12:01:32 -0600</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/Nullable/2008/10/01/Plans_to_the_Death_Star_Or_an_AutoGenerated_EDM.aspx</feedburner:origLink></item>
		<item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/Nullable/2008/09/15/Spoke_at_the_SWFL_Code_Camp_on_Saturday.aspx</guid>
			<link>http://feedproxy.google.com/~r/SingingEelsBlogs/~3/TvhA6YqayRA/Spoke_at_the_SWFL_Code_Camp_on_Saturday.aspx</link>
			<author>Timothy Khouri</author>
			<title>Spoke at the SWFL Code Camp on Saturday</title>
			<description>&lt;p&gt;So South West Florida was on fire this past Saturday (September 14th 2008), as they held their first annual &lt;a href="http://swfldev.net/" rel="nofollow"&gt;SWFL Code Camp&lt;/a&gt;! There were a lot of great people there to kick off the event including John Dunagan who ran the event, &lt;a href="http://www.devfish.net/" rel="nofollow"&gt;Joe Healy&lt;/a&gt;, Microsoft's Developer Evangelist for Florida, and Bob Suess, Microsoft's Developer Evangelist Manager for the "East Region" (basically New York down to Florida).&lt;/p&gt;

&lt;p&gt;The &lt;a href="http://www.fgcu.edu/" rel="nofollow"&gt;campus&lt;/a&gt; was great, the turnout was really good too with 175 registered devs (even though this is a new code camp), and plenty of speakers. There was even an "Open Space" session going on all day encouraging the dev community to open up to expressing their thoughts that much more. Everything went well... except...&lt;/p&gt;

&lt;h3&gt;Jonas Stawski - I.O.U. a Beer!
&lt;/h3&gt;&lt;p&gt;I had the great pleasure of presenting ASP.NET MVC for two sessions, first as an "Intro" then a "Deep Dive", and I had a lot of fun. For my first session, there were about 55 people (the room seemed packed), and I was excited to hook up my laptop to the projector and start my presentation.&lt;/p&gt;

&lt;p&gt;So, why do I owe &lt;a href="http://www.jstawski.com/" rel="nofollow"&gt;Jonas Stawski&lt;/a&gt; a beer? Well, the answer is simple. Even though I just saw Joe Healy use this very same projector... I, unfortunately, could not figure out how to use it... for 15 minutes... not just me, but 4 other people just couldn't get it going.&lt;/p&gt;

&lt;p&gt;So, there I was, doing my presentation to a few dozen developers on a white board! Trying my best to capture their attention over the group of very smart developers trying to get my laptop setup. Then, after 15 long minutes, I see my desktop projected on the screen! Jonas hooked up his laptop to the projector, and used Remote Desktop to go to my laptop, and let me use his for the session.&lt;/p&gt;

&lt;p&gt;Everything went very well from there, except for the fact that Jonas had his session in the next time slot, and so did I. This meant that I had to either figure out how to use my laptop, or try to convince everyone to stay for a riveting white board session :)&lt;/p&gt;

&lt;h3&gt;Stop Being So Stupid Timothy!
&lt;/h3&gt;&lt;p&gt;Between my sessions I realized that this should be very easy, and I must be trying too hard. So, since we tried the keyboard "function + F8" (which simply set the projector to a black screen), and we tried the "Extend the desktop onto this monitor" in the Vista display control panel (which set the projector and my computer to black)... I figured I would look one more time to see if I could figure it out.&lt;/p&gt;

&lt;img src="./Articles/UserImage.aspx?ImageID=64780a0e-52b4-423a-b5a3-7227f099727a" alt="Context menu with NVIDIA Control Panel" title="Context menu with NVIDIA Control Panel" /&gt;

&lt;p&gt;Yup, it was that easy. About 3 seconds after clicking on the NVIDIA Control Panel link there, I saw a radio button "copy this screen to the other". I clicked it, pressed OK, and all was good from there on.&lt;/p&gt;

&lt;h3&gt;ASP.NET MVC Presentations
&lt;/h3&gt;&lt;p&gt;I'm really getting into MVC, TDD and the ASP.NET MVC framework in general, so I'm slated to give another presentation next month at our &lt;a href="http://www.sarasotadev.net/" rel="nofollow"&gt;local developer group&lt;/a&gt;, and I'm hoping to sign up for the Tampa Code Camp when the call for speakers goes out there too.&lt;/p&gt;

&lt;p&gt;And now it's 6:54am on a Monday so the fun is over and it's back to work time!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/TvhA6YqayRA" height="1" width="1"/&gt;</description>
			<pubDate>Mon, 15 Sep 2008 04:32:05 -0600</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/Nullable/2008/09/15/Spoke_at_the_SWFL_Code_Camp_on_Saturday.aspx</feedburner:origLink></item>
		<item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/Nullable/2008/09/04/A_Change_to_the_MVC_ActionSelectionAttribute.aspx</guid>
			<link>http://feedproxy.google.com/~r/SingingEelsBlogs/~3/kMQUZcI3ZZY/A_Change_to_the_MVC_ActionSelectionAttribute.aspx</link>
			<author>Timothy Khouri</author>
			<category>ASP.NET</category>
			<title>A Change to the MVC "ActionSelectionAttribute"?</title>
			<description>&lt;p&gt;ASP.NET MVC currently has the notion of an ActionSelectionAttribute that allows you to aid the MVC framework in choosing which method should handle the Action that the user is choosing. Meaning, if you wanted the user to see the action "/Members/Signup" for both displaying the form, and also handling the posting of the form... but you wanted that to be handled by two different methods in your controller, you would do the following:&lt;/p&gt;

&lt;div class="CodeBlock c#"&gt;[AcceptVerbs(&lt;span class="String"&gt;"GET"&lt;/span&gt;)]&lt;br /&gt;
&lt;span class="KeyWord"&gt;public&lt;/span&gt; ActionResult Signup()&lt;br /&gt;
{&lt;span class="Comment"&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;// ...&lt;/span&gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
[AcceptVerbs(&lt;span class="String"&gt;"POST"&lt;/span&gt;)]&lt;br /&gt;
[ActionName(&lt;span class="String"&gt;"Signup"&lt;/span&gt;)]&lt;br /&gt;
&lt;span class="KeyWord"&gt;public&lt;/span&gt; ActionResult Signup_Submitted()&lt;br /&gt;
{&lt;span class="Comment"&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;// ...&lt;/span&gt;&lt;br /&gt;
}&lt;/div&gt;

&lt;p&gt;This is great, but there is a slight problem (as I see it) with the current implementation of how the default &lt;a href="http://lostintangent.com/2008/07/03/aspnet-mvc-controlleractioninvoker-part-1/" rel="nofollow"&gt;controller action invoker&lt;/a&gt; uses the ActionSelectionAttribute.&lt;/p&gt;

&lt;p&gt;Basically, these attributes have to filter down to only *one* possible result. Meaning, you can't have two methods that could potentially handle the same request. So, this would cause an error:&lt;/p&gt;

&lt;div class="CodeBlock c#"&gt;&lt;span class="Comment"&gt;// This will error, because both &lt;span class="KeyWord"&gt;this&lt;/span&gt; method, and the one&lt;/span&gt;&lt;span class="Comment"&gt;&lt;br /&gt;
// below can handle a &lt;span class="String"&gt;"POST"&lt;/span&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span class="KeyWord"&gt;public&lt;/span&gt; ActionResult Signup()&lt;br /&gt;
{&lt;span class="Comment"&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;// ...&lt;/span&gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
[AcceptVerbs(&lt;span class="String"&gt;"POST"&lt;/span&gt;)]&lt;br /&gt;
[ActionName(&lt;span class="String"&gt;"Signup"&lt;/span&gt;)]&lt;br /&gt;
&lt;span class="KeyWord"&gt;public&lt;/span&gt; ActionResult Signup_Submitted()&lt;br /&gt;
{&lt;span class="Comment"&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;// ...&lt;/span&gt;&lt;br /&gt;
}&lt;/div&gt;

&lt;p&gt;I would personally like to see this attribute modified slightly to allow a "precedence" value. This way, if multiple methods can be selected, MVC can figure out which *one* should be used instead of throwing an error.&lt;/p&gt;

&lt;p&gt;This may not seem like a big deal with the scenario above, but imagine a more complicated one:&lt;/p&gt;

&lt;div class="CodeBlock c#"&gt;[ActionName(&lt;span class="String"&gt;"DisplayLetter"&lt;/span&gt;)]&lt;br /&gt;
[AcceptHeaders(&lt;span class="String"&gt;"application/ms-word"&lt;/span&gt;, Precedence=1)]&lt;br /&gt;
&lt;span class="KeyWord"&gt;public&lt;/span&gt; ActionResult DisplayLetter_AsWord(&lt;span class="KeyWord"&gt;int&lt;/span&gt; letterID)&lt;br /&gt;
{&lt;span class="Comment"&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;// ...&lt;/span&gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
[ActionName(&lt;span class="String"&gt;"DisplayLetter"&lt;/span&gt;)]&lt;br /&gt;
[AcceptHeaders(&lt;span class="String"&gt;"application/pdf"&lt;/span&gt;, Precedence=2)]&lt;br /&gt;
&lt;span class="KeyWord"&gt;public&lt;/span&gt; ActionResult DisplayLetter_AsPdf(&lt;span class="KeyWord"&gt;int&lt;/span&gt; let)&lt;br /&gt;
{&lt;span class="Comment"&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;// ...&lt;/span&gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span class="KeyWord"&gt;public&lt;/span&gt; ActionResult DisplayLetter(&lt;span class="KeyWord"&gt;int&lt;/span&gt; let)&lt;br /&gt;
{&lt;span class="Comment"&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;// ...&lt;/span&gt;&lt;br /&gt;
}&lt;/div&gt;

&lt;p&gt;Now it all starts to make a little more sense... well, to me at least. A request could come in from a user who accepts both ms-word and pdf's!!! So, which method gets called? Ahh, the precedence will determine that!&lt;/p&gt;

&lt;p&gt;Any thoughts?&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/kMQUZcI3ZZY" height="1" width="1"/&gt;</description>
			<pubDate>Thu, 04 Sep 2008 07:47:34 -0600</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/Nullable/2008/09/04/A_Change_to_the_MVC_ActionSelectionAttribute.aspx</feedburner:origLink></item>
		<item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/Nullable/2008/08/14/How_to_Handle_Side_Content_in_ASPNET_MVC.aspx</guid>
			<link>http://feedproxy.google.com/~r/SingingEelsBlogs/~3/q-xrDmTQUJk/How_to_Handle_Side_Content_in_ASPNET_MVC.aspx</link>
			<author>Timothy Khouri</author>
			<category>ASP.NET</category>
			<title>How to Handle "Side Content" in ASP.NET MVC</title>
			<description>&lt;p&gt;A couple of days ago, Stephen Walther made a great post (&lt;a href="http://weblogs.asp.net/stephenwalther/archive/2008/08/12/asp-net-mvc-tip-31-passing-data-to-master-pages-and-user-controls.aspx" rel="nofollow"&gt;ASP.NET MVC Tip #31 – Passing Data to Master Pages and User Controls&lt;/a&gt;) on a subject that is bound to come up 100 times more until MVC is fully understood. This post is a follow-up to that one, in hopes to have a clear sense of what to do with the issue.&lt;/p&gt;

&lt;p&gt;The issue is as follows: MVC is rests on the pillars of 1) Testability and 2) Single Responsibility. Every function (action, page, whatever you want to call it) should be fully testable, and it should only handle one point of concern. So the question is, how do we handle supplemental data?&lt;/p&gt;

&lt;h3&gt;Our Scenario
&lt;/h3&gt;&lt;p&gt;Imagine if you built an MVC web application for a car dealership that had the following actions (or pages):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Home - ContactUs&lt;/li&gt;
&lt;li&gt;Home - OurLocations&lt;/li&gt;
&lt;li&gt;Vehicles - ListCars&lt;/li&gt;
&lt;li&gt;Vehicles - ViewCarDetail&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At first glance, this would be very straight forward and very easy to solve (and it is). I would make a "HomeController" and have the ContactUs and OurLocations actions there, and I would make a "VehiclesController" and put the ListCars and ViewCarDetail actions there. So Where's the Problem?&lt;/p&gt;

&lt;h3&gt;A Slightly More Complex Page
&lt;/h3&gt;&lt;p&gt;Imagine, though, if you didn't just want to list all the cars on the "ListCars" page. What would you do if you wanted to also show the "Top 5 Custom Testimonials" in a &amp;lt;div&amp;gt; on the right side of the page. You want to have that shown on both of the 'vehicles' pages (ListCars and ViewCarDetail).&lt;/p&gt;

&lt;p&gt;So the question comes in... "Who's responsibility is it to retrieve that data from the data store?" Would you add that code to each function?&lt;/p&gt;

&lt;div class="CodeBlock c#"&gt;&lt;span class="KeyWord"&gt;public&lt;/span&gt; ActionResult ListCars()&lt;br /&gt;
{&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;GetTestimonials();&lt;span class="Comment"&gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;// Now &lt;span class="KeyWord"&gt;do&lt;/span&gt; the ListCars stuff???&lt;/span&gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span class="KeyWord"&gt;public&lt;/span&gt; ActionResult ViewCarDetail()&lt;br /&gt;
{&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;GetTestimonials();&lt;span class="Comment"&gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;// Now &lt;span class="KeyWord"&gt;do&lt;/span&gt; the ViewCarDetail stuff???&lt;/span&gt;&lt;br /&gt;
}&lt;/div&gt;

&lt;p&gt;You would *NEVER* want to do the above as that is a 100% violation of one of the pillars of MVC (the Single Responsibility Principle). Not to mention that you're working harder than you have to.&lt;/p&gt;

&lt;p&gt;Would you make a custom ActionFilter and decorate your methods?&lt;/p&gt;

&lt;div class="CodeBlock c#"&gt;[TestimonialGetter]&lt;br /&gt;
&lt;span class="KeyWord"&gt;public&lt;/span&gt; ActionResult ListCars()&lt;br /&gt;
{&lt;span class="Comment"&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;// Now &lt;span class="KeyWord"&gt;do&lt;/span&gt; the ListCars stuf???&lt;/span&gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
[TestimonialGetter]&lt;br /&gt;
&lt;span class="KeyWord"&gt;public&lt;/span&gt; ActionResult ViewCarDetail()&lt;br /&gt;
{&lt;span class="Comment"&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;// Now &lt;span class="KeyWord"&gt;do&lt;/span&gt; the ViewCarDetail stuf???&lt;/span&gt;&lt;br /&gt;
}&lt;/div&gt;

&lt;p&gt;That's hideous, and is simply putting a new dress on an old wench. So then, what do we do?&lt;/p&gt;

&lt;h3&gt;Look At the Data for What It Is
&lt;/h3&gt;&lt;p&gt;The problem here is that we're losing focus of what the data really is. That supplemental data is not the main focus of the "View", and it's throwing us off. If we didn't have that "Top 5 Testimonials" stuff, we wouldn't have a problem.&lt;/p&gt;

&lt;p&gt;To prove my point, imagine if we didn't want to show "Top 5 Testimonials", but instead we wanted to show... let's say... the logged in user's name! Would that be so hard?&lt;/p&gt;

&lt;p&gt;"That's easy", you say, "all I have to do is &amp;lt;%= User.Identity.Name %&amp;gt;". True, that is easy. But did you notice that we're not freaking out about the fact that we just got some "data" from a "data base" and displayed it in our View :)&lt;/p&gt;

&lt;p&gt;The same is true for other, non-view-specific data. So, to solve our issue above, we would most-likely create a base class for our Vehicles controller that got that extra data (in the constructor) and put the needed info into the ViewData collection.&lt;/p&gt;

&lt;p&gt;Is that testable? Does that allow a single responsibililty? Yes, it is and yes it does. In your testing framework, you would mock up the data store, and then you could test each action to make sure that it has all the data (including the Top 5 Testimonials stuff).&lt;/p&gt;

&lt;h3&gt;Important Conclusion
&lt;/h3&gt;&lt;p&gt;MVC is a great design pattern, and it's been around for a long time. However, ASP.NET MVC is new, and there will likely be many revisions and redefinitions to how it will address issues like this. But as long as you keep to the guidelines of MVC then you will be able to reap it's benefits.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/q-xrDmTQUJk" height="1" width="1"/&gt;</description>
			<pubDate>Thu, 14 Aug 2008 07:32:38 -0600</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/Nullable/2008/08/14/How_to_Handle_Side_Content_in_ASPNET_MVC.aspx</feedburner:origLink></item>
	</channel>
</rss>
