The persistence mechanism within LINQ can bite you if you aren't careful. The framework will persist a local copy of the data, so be careful when making database edits directly as this can cause the data in the application to become out of sync with the data LINQ believes is available.
It is necessary to recycle the application after a direct edit is made.
I realize that the code is too wide -- if you copy it, it will be ok<g> I wanted a better way to provide a quick means of passing messages (in this case for error feedback to the user) for the view from the controller without using ViewData. ViewData is nice as a bag, but having to write code the checks to see if a specific value is present in the ViewData, and the render accordingly gets tedious and redundant. So, I created a pair reusable Controller and ViewPage class definitions that would allow a message to be passed simply by setting a property. The value in this property is available for 1 cycle, so its similar to a Flash in RoR.
MyController.cs
Here I've added the FlashError property that gives us easy access to the session value:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
namespace MyMvcApplication
{
public class MyController : Controller
{
protected string FlashError
{
get
{
if (null != System.Web.HttpContext.Current.Session["FlashError"])
{
return System.Web.HttpContext.Current.Session["FlashError"].ToString();
}
return null;
}
set
{
System.Web.HttpContext.Current.Session["FlashError"] = value;
}
}
protected override void OnActionExecuted(FilterExecutedContext filterContext)
{
base.OnActionExecuted(filterContext);
// FlashError = null;
}
}
}
MyViewBase.cs
The view has the same definition for FlashError, but the Render(FlashError) method here is of interest:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.UI;
using System.IO;
using System.Xml.Linq;
using System.Web.UI.HtmlControls;
namespace MyMvcApplication
{
public class MyViewBase : ViewPage
{
protected string FlashError
{
get
{
if (null != System.Web.HttpContext.Current.Session["FlashError"])
{
return System.Web.HttpContext.Current.Session["FlashError"].ToString();
}
return null;
}
set
{
System.Web.HttpContext.Current.Session["FlashError"] = value;
}
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
RenderFlashError();
base.Render(writer);
}
protected virtual void RenderFlashError()
{
if (!string.IsNullOrEmpty(FlashError))
{
Control errorTextControl = this.Find<Control>("errortext");
if (null != errorTextControl)
{
try
{
errorTextControl.Controls.Clear();
errorTextControl.Controls.Add(new LiteralControl(FlashError));
}
catch (System.Web.HttpException e)
{
if (e.Message.Contains("blocks"))
{
}
else
{
throw e;
}
}
}
FlashError = null;
}
}
}
}
Basically, we check to see if the FlashError is available, and if it is we recursively search the id "flasherror". If found, the inner contents are replaced with the value of the FlashError property. Immediately afterwards, the value is destroyed.
You'll notice the use of the Find<T> extension method -- this was gratuitously swiped from Here. Unfortunately, I cannot provide credit to the author by anything other than "FlatLiner".
If there is interest, I can post a demo.
Earlier, my business partner forwarded me a link to a great article by Mircea Trofin that covers, with examples, some great design guidlines for using LINQ and developing/extending with new types, libraries and the like.
The article is a great read for those of you who like an architectural view.
Check it out:
http://blogs.msdn.com/mirceat/archive/2008/03/13/linq-framework-design-guidelines.aspx
Recently I had to move an entire folder of MP3s from one server to another, and it just seemed silly to have to tar and transfer. Here's how to do it with SCP:
find . -name "*.extension" -print0 | xargs -0 tar cvf - | ssh username at server tar xf -
Hope this helps...
My company offers full-service software development -- and recently started using Umbraco as our CMS platform of choice. Check out the new site.
http://www.webglimmer.com
A very cool idea indeed.
Check it out
I've recently been playing with a new browser called Flock. Check it out.
http://www.flock.com
Blogged with Flock

At 06:37pm EST on August 8th, 2007, Space Shuttle Endeavour lit her fires and lifted off, headed for the cosmos for a rendezvous with the ISS on its planned 11 day mission to provide supplies and deliver scientific experiments in SPACEHAB's logistics module.
Led by commander Scott Kelly, Endeavour's launch provided me with an experience that will leave me forever changed. I brought my Nikon D80 and my 300mm lens to capture the moment but before I deliver the photos, let me first say that I was only able to take photos for the first few seconds. Once the sound hit me, I was so awe struck that the camera went to my side and all I could do was watch.
As I am sure you can intuit, this was my first Space Shuttle launch. I was fighting back tears. This amazing achievement of our human race -- I felt a oneness with everyone on the planet. To see what a group of minds can accomplish; millions of moving parts, timings, and precision of unfathomable scale. I was not successful in holding back all of my emotions -- goosebumps, and yes a few tears.
I digress -- I was able to squeeze off a few shots of which I am extremely proud. One I sent to CNN, and to my surprise, I actually got a call back in less than five minutes. They wanted first to verify that the photo was taken today due to the fact that I was able to get a higher contrast in my pictures than their previous submissions. In fact, they requested a version that had more of the haze found in the others they had received so that, "... we won't have to explain to our viewers why some photos are light and hazy, and yours is so clean..." This is my first published photo, and by CNN! I couldn't be more overwhelmed. What a day.
Here they are:



I'm sitting in the Las Vegas McCarran airport, waiting for my connecting flight to Orlando -- enroute to Titusville for tomorrow's Space Shuttle launch. I was informed this morning as I was leaving the house that we're looking at an 80% chance for launch.
My insider at NASA says that that's about the best you could hope for -- it doesn't get better than that.
So I'll keep my fingers crossed -- I hope to deliver some awesome photos and a full report upon my return. That is, if I can wait that long after I see it :).
Through the still dawn air
I do not find it
Nor in the later hours is it found
Not in the recesses of the breaks
Urban mountains rest
A pin drop? No --
A whisper? Hardly --
An unobtainable substance without matter
Matters most to those that do not have it
For I, I do not have it -- Not here, not now
It is not, I am not
Silence
Deep Thought
Union Square gentleman enjoying tunes and deep in thought.
Animated Chess
Friendly games of chess.
Meat anyone?
New Yorker's will recognize this meat house.
Looking up Madison Ave.
Lady on the water
A lovely statue in North Central Park
New York Castle -- Actually a fort
Urban Preacher
This gentleman spent his afternoon preaching from the steps of Union Square in New York, NY. He was praising the efforts of Marx, the Buddha and Ra, the Egyptian sun god.
He was not happy about having his picture taken -- until I showed it to him. He gave his approval.
The Making of Friends
Two 'pedes of some kind are making friends in Union Square under a tree.
These two started at opposite ends of a long fence and found their way to one another.
Nap Time
Union Square is a great place for an afternoon bench nap. This fellow didn't even move during the brief (30 seconds) rain storm that interrupted most people in the grass.
Zen, and the art of the Bench
Enjoying tunes on the bench through my many rounds through the park. In all actuality, I'm not sure if they were tunes, or some kind of self guided meditation. I don't believe he moved once.

Most likely you are sitting there reading this blog over a high speed Internet connection while your chicken cacciatore dinner is being micro-waved and ready in about three minutes and your IFC in theaters movie from your On Demand cable service sits paused and ready to resume once your near-instant Italian food is ready.
Or, perhaps you didn't even have to experience the inconvenience of having to wait until you got home to ready this entry -- you may be sitting there in traffic thumbing through the vast accumulation of all human knowledge with a few flicks of your deft digit. That's sure better than a trip to the library.
All that assuming you are reading this at all -- perhaps you have chosen to have this entry read to you by your computer so that you are better able to consume the food, or more importantly drive your vehicle.
I should interject at this point that I am huge fan of the amazing technological advances that have brought us such things as high-speed everything, wireless everything, and instant everything -- at a cost that the vast majority can afford... After all, if we had to wait (read: save up some money) what kind of crap would that be?
But, like many others I have noticed that while these instruments have been invented and thrust into our mainstream culture in an effort to improve our lives, and to bring us "closer together" (a popular theme in marketing today), it seems as though the effect has been this idea's antithesis. With every task we automate and delegate, we become less -- and less a part of our own lives.
Sure, I can beam twenty emails out in an hour (so, I type slowly...) and accomplish in that time what would take many hours by telephone not to mention the days that would be consumed should I have a momentary lapse into insanity and up a pen and paper to send something via the aptly named, "Snail Mail." But what about the old adage, that life is about "Quality, not quantity?" We are consumed by the need for speed and for instant gratification. Just turn on any cable channel and you will see a dozen commercials claiming almost instant weight loss via their revolutionary formula derived from some South African shrub-root.
And whilst I am on the subject of weight loss, I recently undertook the arduous task... Scratch that -- I am still undertaking the arduous task of getting into shape. Let's face it -- It's a lifelong task -- you know it yourself even if you don't like it.
I digress. I started in April at 279 on about the 20th. Here we are at July 17th and I am sitting comfortably (everything is relative, remember?) on an American Airlines puddle jumper on my way to New York city. I'm not crowding my neighbors and I am actually able to use my laptop without forcing a dent into my belly. Specifically, I've lost almost seventy pounds in that time. Lets see, April-May, May-June, June-July. Three months. People have been constantly asking me for my secret, and alas have been consistently disappointed. Eat right -- Veggies, cut out as much fat as you can, etc. Learn your BMR (Basil Metabolic Rate: The number of calories that should be consumed by a person to maintain their current body weight based on their activity level) and consume less. Exercise three or more times a week (I try for 5 times) for thirty or more minutes (ten to reach your target heart rate and twenty minutes maintaining it).
Now, if you watch any of these commercials -- they promise your similar results in similar time (and if you pay attention you'll always read in fine print, or some actually state that you must consider proper diet and exercise... and don't forget the little white letters at the bottom that read, results not typical) -- "I lost 38 pounds in six weeks with ABC Product!" Lets do some math... 38lbs / 6 = 6.34lbs. That's 6.34 pounds per week. I did about six pounds per week without any supplements, and without spending the serious cash involved in purchasing the products themselves, or in some extreme cases the hospital costs incurred after a bad reaction to these non-fda approved weight loss programs. Did I mention that I feel great?
Tangents aside -- We must stop expecting something for nothing. We must begin to appreciate our grandmother's/grandfathers advice -- listen to those who came from a simpler time and allow their wisdom to permeate your existence. It's so simple -- they may not be able to operate your G4, or your Quad Xeon or your iPhone -- but I'd like to remind you of what our recent ancestors handled: Big wars, depressions, recessions, assassinations, conspiracies and how apparently well they did.
Next time you want to see a movie, go and see it in the theater... or rent it. Next time you want chicken cacciatore, go to a restaurant and order it... or better yet, learn to prepare it. The next time you find yourself buying a gadget to save yourself time... sit down and do it the old fashioned way. Don't live your life On Demand, demand that you love your life.
More Posts
Next page »