<?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:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>naspinski</title>
    <description>development :: programming :: design</description>
    <link>http://naspinski.net/</link>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>BlogEngine.Net Syndication Generator 1.0.0.0 (http://dotnetblogengine.net/)</generator>
    <language>en-GB</language>
    <blogChannel:blogRoll>http://naspinski.net/opml.axd</blogChannel:blogRoll>
    <blogChannel:blink>http://www.naspinski.net/syndication.axd</blogChannel:blink>
    <dc:creator>naspinski</dc:creator>
    <dc:title>naspinski</dc:title>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/naspinski" /><feedburner:info uri="naspinski" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
      <title>Helper Methods for Validating Generated Linq-to-Entities edmx Files using Partial Classes</title>
      <description>&lt;h2&gt;Centralized client and server side validation as well as property and method additions to auto-generated classes&lt;/h2&gt;Say I have an auto-generated &lt;strong&gt;Widget&lt;/strong&gt; class (from a database, generated into a .edmx file):
&lt;pre class="prettyprint"&gt;namespace My.NameSpace
{
    public partial class Widget
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
}&lt;/pre&gt;
&lt;br /&gt;
Now I want to add some methods and validation to the class, but I do not want to edit the class directly.  What I need to do is make a partial class and add the things in there.  This accomplished two things: 1. separates logic from structure and 2. separates the files so another auto-generation or update will not lose the work you do.  This is very simple to do, here is an example:
&lt;pre class="prettyprint"&gt;// be SURE that it is in the same namespace
namespace My.NameSpace
{
    //System.ComponentModel.DataAnnotations
    [MetadataType(typeof(VWidget))]
    public partial class Widget
    {
        // I want to add another property
        public string FullName
        { get { return Name + Id; } }
    }

    // this is the validation segment
    // this is the same as the class name above
    public class VWidget
    {
        [Display(Name = "Widget Name")]
        [Required]
        [StringLength(50)]
        public string Name { get; set; }
    }
}&lt;/pre&gt;
&lt;br /&gt;
Now this was very simple, but it shows how to add this in.  First of all, there is a new property to &lt;strong&gt;Widget&lt;/strong&gt; called 'FullName' which will combine the 'Name' and 'Id' properties.  Not really all that useful, but you can see how it is used.
&lt;br /&gt;&lt;br /&gt;
The next part is really cool, you can put all of your validation in the 'VWidget' class (name doesn't really matter here).  Here you can see that 'Name' is now required, has a max length of 50 characters, and a label will display "Widget Name" instead of the default property name.  This way, if you are using this library with MVC, you can do something this simple:
&lt;pre class="prettyprint"&gt;@using (Html.BeginForm())
{ 
    @Html.ValidationSummary()
    @Html.LabelFor(x =&gt; x.Name)
    @Html.EditorFor(x =&gt; x.Name)
}&lt;/pre&gt;
&lt;br /&gt;
And you will be pushing client-side validation as well as a centralized area to hold your custom labels.  On top of that, in your code, if you simply include:
&lt;pre class="prettyprint"&gt;if (ModelState.IsValid)&lt;/pre&gt;&lt;br /&gt;
You will be enforcing server-side validation as well.&lt;br /&gt;&lt;br /&gt;Later I will get into how you can use .resx files for localization and centralization along with these partial classes.
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/MbOs3D6p67dxr98mpvM8xDUvS4w/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MbOs3D6p67dxr98mpvM8xDUvS4w/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/MbOs3D6p67dxr98mpvM8xDUvS4w/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MbOs3D6p67dxr98mpvM8xDUvS4w/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=uCJe7duGfkU:Xc_YFRHc7OE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=uCJe7duGfkU:Xc_YFRHc7OE:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=uCJe7duGfkU:Xc_YFRHc7OE:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=uCJe7duGfkU:Xc_YFRHc7OE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=uCJe7duGfkU:Xc_YFRHc7OE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/uCJe7duGfkU" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/uCJe7duGfkU/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Helper-Methods-for-Validating-Generated-Linq-to-Entities-edmx-Files-using-Partial-Classes.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=a406ea12-987c-46df-971e-5721bd2251e3</guid>
      <pubDate>Tue, 07 Feb 2012 00:48:00 -0500</pubDate>
      <category>c#</category>
      <category>steal some code</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=a406ea12-987c-46df-971e-5721bd2251e3</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=a406ea12-987c-46df-971e-5721bd2251e3</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Helper-Methods-for-Validating-Generated-Linq-to-Entities-edmx-Files-using-Partial-Classes.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=a406ea12-987c-46df-971e-5721bd2251e3</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=a406ea12-987c-46df-971e-5721bd2251e3</feedburner:origLink></item>
    <item>
      <title>Ternary Operator in SQL</title>
      <description>&lt;h2&gt;there technically isn't one, but an equivalent isn't too hard to do&lt;/h2&gt;

This ternary in C#:
&lt;pre class="prettyprint"&gt;(str.Length &gt; 0 ? "yes" : "no");&lt;/pre&gt;
&lt;br /&gt;

Is equivalent to this in SQL:
&lt;pre class="prettyprint"&gt;(CASE WHEN LEN(@str) &gt; 0 THEN "yes" ELSE "no" END);&lt;/pre&gt;
&lt;br /&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/qEJ7st0i3BSngkWZfIaz6oLS8Ck/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qEJ7st0i3BSngkWZfIaz6oLS8Ck/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/qEJ7st0i3BSngkWZfIaz6oLS8Ck/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qEJ7st0i3BSngkWZfIaz6oLS8Ck/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=q1N9ecltmi8:_k0BX-FLtAI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=q1N9ecltmi8:_k0BX-FLtAI:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=q1N9ecltmi8:_k0BX-FLtAI:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=q1N9ecltmi8:_k0BX-FLtAI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=q1N9ecltmi8:_k0BX-FLtAI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/q1N9ecltmi8" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/q1N9ecltmi8/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Ternary-Operator-in-SQL.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=1be7efe3-cf91-4bc0-afe4-707419bcf61b</guid>
      <pubDate>Fri, 03 Feb 2012 13:32:00 -0500</pubDate>
      <category>sql</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=1be7efe3-cf91-4bc0-afe4-707419bcf61b</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=1be7efe3-cf91-4bc0-afe4-707419bcf61b</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Ternary-Operator-in-SQL.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=1be7efe3-cf91-4bc0-afe4-707419bcf61b</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=1be7efe3-cf91-4bc0-afe4-707419bcf61b</feedburner:origLink></item>
    <item>
      <title>Using a Custom Controller Class in Asp.Net MVC to Simplify Coding</title>
      <description>&lt;h2&gt;Controllers often have some repetitive code, implementing your own Controller class can help eliminate a lot of this&lt;/h2&gt;

Here is a small snippet and how I use some simple tricks to help clean up my Controllers in Asp.Net MVC (using MVC 4 at the moment):

&lt;pre class="prettyprint"&gt;public class MyController : Controller
{
    public MyEntities Db { get; set; }

    protected override void OnActionExecuting(
        ActionExecutingContext filterContext)
    {
        if (filterContext.IsChildAction)
            return;
        this.Db = new MyEntities();
        base.OnActionExecuting(filterContext);
    }

    [HttpPost]
    public ActionResult Index(FormCollection form)
    {
        string srch = form["Search"] ?? string.Empty;
        return RedirectToAction("Index", 
            new { search = srch });
    }

    protected void AttachToDb(EntityObject obj, 
        bool save = false, string entityKeyField = "Id")
    {
            obj.EntityKey = new EntityKey(
                obj.ToPluralizedString(), entityKeyField, 
                obj.GetType().GetProperty("Id")
                .GetValue(obj, null));
            Db.Attach(obj);
            Db.ObjectStateManager.ChangeObjectState(
                obj, System.Data.EntityState.Modified);
            if (save) Db.SaveChanges();
    }
}&lt;/pre&gt;
&lt;br /&gt;
The first thing in the code is simple declaration of an EntityContext - this is implemented directly, but could (and usually should) be implemented differently for dependency injection, but you get the idea.  Here is where I also like to include stuff that is often used and could be vital (and centralized) for an application like an output type for web services (JSON, XML, etc.).
&lt;br /&gt;&lt;br /&gt;  
Next the &lt;span style="font-weight:bold"&gt;OnActionExecuting&lt;/span&gt; is over-ridden and the Context is initialized.  Here is where you can initialize the properties you set above.
&lt;br /&gt;&lt;br /&gt;
The next method, the &lt;span style="font-weight:bold"&gt;HttpPost Index&lt;/span&gt; method is just an example of how often times you can consolidate a commonly used method.  For this example, it was from an application that had searches on all index pages.  Instead of repeating this code in every controller, you can just put it here.
&lt;br /&gt;&lt;br /&gt;
The final method has become very useful.  A use I often find, is when taking in a large model after an Asp.Net MVC POST event, I can attach the model to the Db generically without any extra work&lt;br /&gt;
&lt;br /&gt;
This method is a bit confusing, but it is simply attaching the new model to the Db without a Db lookup.  In my tables, I generally have a field 'Id' that houses the Primary Key of every table, whether it is an Int or Guid.  This way, I can simply pass in whatever object I am currently working with, and by using the &lt;a href="http://naspinski.net/post/Pluralize.aspx"&gt;pluralize&lt;/a&gt; method, and reflection, the method can figure out which table to attach the model to - eliminating the need for me to do extra coding.  Alternatively, if I want to change the Key from 'Id', I can pass that in as well.
&lt;br /&gt;&lt;br /&gt;
Now when I get a model being POSTed, it is easy to deal with:
&lt;pre class="prettyprint"&gt;[HttpPost]
public ActionResult Edit(Widget model)
{
    if(ModelState.IsValid)
    {
        AttachToDb(model, true);
        //do stuff
    }
    else { /*do other stuff*/ }
}&lt;/pre&gt;
&lt;br /&gt;
This avoids the need to take another trip to the DB, change the properties on the object, then submit - streamlining the process very much and cutting down a lot of code.
&lt;br /&gt;&lt;br /&gt;
This would be an example of how this would be done manually with the normal Controller class:

&lt;pre class="prettyprint"&gt;[HttpPost]
public ActionResult Edit(Widget model)
{
    if(ModelState.IsValid)
    {
        MyEntities db = new MyEntities();
        Widget w = db.Widgets.Single(x =&gt; x.Id == model.Id);
        w.Name = model.Name;
        w.Serial = model.Serial;
        db.SaveChanges();
        //do stuff
    }
    else { /*do other stuff*/ }
}&lt;/pre&gt;
&lt;br /&gt;
Not a huge difference when you are just getting 2 values, but you could see how a model with 20 or 30 fields can be cut down from 30+ lines to just 1 or 2.
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/y8MWNV3gvqGvSbFh6AGb0NRiVAw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/y8MWNV3gvqGvSbFh6AGb0NRiVAw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/y8MWNV3gvqGvSbFh6AGb0NRiVAw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/y8MWNV3gvqGvSbFh6AGb0NRiVAw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=x0Ppx4GneJk:_WxJ0QBWaW0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=x0Ppx4GneJk:_WxJ0QBWaW0:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=x0Ppx4GneJk:_WxJ0QBWaW0:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=x0Ppx4GneJk:_WxJ0QBWaW0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=x0Ppx4GneJk:_WxJ0QBWaW0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/x0Ppx4GneJk" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/x0Ppx4GneJk/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Using-a-Custom-Controller-Class-in-AspNet-MVC-to-Simplify-Coding.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=0683e027-19b8-44ba-9335-a238370f29f0</guid>
      <pubDate>Thu, 15 Dec 2011 13:23:00 -0500</pubDate>
      <category>asp.net</category>
      <category>c#</category>
      <category>mvc</category>
      <category>steal some code</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=0683e027-19b8-44ba-9335-a238370f29f0</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=0683e027-19b8-44ba-9335-a238370f29f0</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Using-a-Custom-Controller-Class-in-AspNet-MVC-to-Simplify-Coding.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=0683e027-19b8-44ba-9335-a238370f29f0</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=0683e027-19b8-44ba-9335-a238370f29f0</feedburner:origLink></item>
    <item>
      <title>Pluralize a String or Class Name in C# and .Net</title>
      <description>&lt;h2&gt;Sometimes you need to pluralize names like when you are working with Entity Framework or countless other sitautaions&lt;/h2&gt;

When you auto-generate from tables in Entity Framework, it will make the table names plural, and the objects singular.  Often times, when you are trying to use more generic functions like creating EntityKey objects for attaching to an unknown table, you will need to pluralize a class name, so for this, I came up with a couple static methods to simply return a plural version of an Object's name or a string itself:

&lt;pre class="prettyprint"&gt;using System.Data.Entity.Design.PluralizationServices;
using System.Globalization;

public static string Pluralize(this string s)
{
    PluralizationService plural = 
        PluralizationService.CreateService(
            CultureInfo.GetCultureInfo("en-us"));
    return plural.Pluralize(s);
}&lt;/pre&gt;
&lt;br /&gt;

Simple enough, now I make this specifically to get the table name of an EntityObject:
&lt;pre class="prettyprint"&gt;public static string GetTableName(this EntityObject obj)
{
    return obj.GetType().Name.Pluralize();
}&lt;/pre&gt;

&lt;br /&gt;
In use:
&lt;pre class="prettyprint"&gt;//returns "Cats":
string cats = "Cat".Pluralize();

//now specifically for EntityObjects:
string tableName = MyEntityObject.GetTableName();&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-yl1gsY0ra4BbASn_mUABBtZlmk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-yl1gsY0ra4BbASn_mUABBtZlmk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-yl1gsY0ra4BbASn_mUABBtZlmk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-yl1gsY0ra4BbASn_mUABBtZlmk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=4V9tUCgBdnw:AE63cOnz-oI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=4V9tUCgBdnw:AE63cOnz-oI:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=4V9tUCgBdnw:AE63cOnz-oI:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=4V9tUCgBdnw:AE63cOnz-oI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=4V9tUCgBdnw:AE63cOnz-oI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/4V9tUCgBdnw" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/4V9tUCgBdnw/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Pluralize.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=4dab230a-b778-4cee-8b6b-d83c3b46c25e</guid>
      <pubDate>Thu, 08 Dec 2011 22:13:00 -0500</pubDate>
      <category>c#</category>
      <category>entities</category>
      <category>linq-to-sql</category>
      <category>mvc</category>
      <category>steal some code</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=4dab230a-b778-4cee-8b6b-d83c3b46c25e</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=4dab230a-b778-4cee-8b6b-d83c3b46c25e</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Pluralize.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=4dab230a-b778-4cee-8b6b-d83c3b46c25e</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=4dab230a-b778-4cee-8b6b-d83c3b46c25e</feedburner:origLink></item>
    <item>
      <title>My Case For Using Both UNIQUEIDENTIFIER (Guid) -and- INT Ids in every database table</title>
      <description>&lt;h2&gt;Case for dual database accessors (not keys) - Guid vs Int/UniqueIdentifier vs Int&lt;/h2&gt;
Let's face it, you never know what exactly is going to end up with your next application.  Has an application ever ended up exactly where it was planned in the beginning?  I would say never.
&lt;br /&gt;&lt;br /&gt;
There is an &lt;a href="http://www.google.com/search?gcx=c&amp;sourceid=chrome&amp;ie=UTF-8&amp;q=primary+key+guid+vs+int"&gt;insane amount of writing on the debate of int vs guid&lt;/a&gt;, both have their pros and cons, both have storage, index and coding implications and we know (or can find) almost all of them with a simple search.  Yet there is no consensus on which is the best, I am not here to add to that discussion. 
&lt;br /&gt;&lt;br /&gt;
Therefore I propose using BOTH - hear me out.
&lt;br /&gt;&lt;br /&gt;
I propose that the best solution is to provide ONE of the two as your primary key, I prefer Guid as the PK, as it can be referenced more universally (think recycle bin, etc.), but it does have the added indexing cost of being larger; then simply add the auto-incrementing integer as an additional field.  Whichever one you choose as your alternative (integer in my case) is simply as a just-in-case means of accessing your data - also indexed.  This provides you the best of both worlds, without too much sacrifice.  For example, you get the ubiquity of being able to generate a Guid anywhere (without a DB trip), but also have the ability to access your data by a clean 4-bit integer.  If for some reason, the code is accessed by software that relies on integers, you are not stuck without one, and vice-versa.
&lt;br /&gt;&lt;br /&gt;
Yes, this will obviously cause more data to be stored for every entry in a table (I am talking about main tables here, not necessarily lookup tables, etc.).  This will cause extra index storage as well, but in the long run, I feel it provides enough advantage and future-proofing to justify the sacrifice.  Now tell me how wrong I am...
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/_mFuqoLD5kOGih0nuGvSYAA6dlo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_mFuqoLD5kOGih0nuGvSYAA6dlo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/_mFuqoLD5kOGih0nuGvSYAA6dlo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_mFuqoLD5kOGih0nuGvSYAA6dlo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=-FoeXs1zVQk:xAvkI5Nw7Z4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=-FoeXs1zVQk:xAvkI5Nw7Z4:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=-FoeXs1zVQk:xAvkI5Nw7Z4:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=-FoeXs1zVQk:xAvkI5Nw7Z4:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=-FoeXs1zVQk:xAvkI5Nw7Z4:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/-FoeXs1zVQk" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/-FoeXs1zVQk/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/My-Case-For-Using-Both-UNIQUEIDENTIFIER--and--INT-Ids-in-every-database-table.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=6874e26b-f463-431f-a290-f299f4e6c5fe</guid>
      <pubDate>Mon, 07 Nov 2011 17:39:00 -0500</pubDate>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=6874e26b-f463-431f-a290-f299f4e6c5fe</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=6874e26b-f463-431f-a290-f299f4e6c5fe</trackback:ping>
      <wfw:comment>http://naspinski.net/post/My-Case-For-Using-Both-UNIQUEIDENTIFIER--and--INT-Ids-in-every-database-table.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=6874e26b-f463-431f-a290-f299f4e6c5fe</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=6874e26b-f463-431f-a290-f299f4e6c5fe</feedburner:origLink></item>
    <item>
      <title>Constraining Routes in MVC to an Enum the Easy Way</title>
      <description>&lt;h2&gt;simple way to constrain a route to only allow enum values&lt;/h2&gt;
Say I have the following enum:
&lt;pre class="prettyprint"&gt;public enum SearchType { Facilities, Courses, Exercises};&lt;/pre&gt;
&lt;br /&gt;
And I only want those the be available in route &lt;string&gt;Search/{SearchType}&lt;/strong&gt;.  I could constrain it manually with a string, but then what if the enum changes and I have this in a bunch of routes?  Here is a simple way to accomplish this constraint:
&lt;pre class="prettyprint"&gt;public static void RegisterRoutes(RouteCollection routes)
{
    List&lt;string&gt; searchTypeL = new List&lt;string&gt;();
    foreach (Enums.SearchType type in 
        Enum.GetValues(typeof(Enums.SearchType))) 
    { searchTypeL.Add(type.ToString()); }
    string searchTypes = string.Join("|", searchTypeL);
    
    routes.MapRoute(
        "Searches",
        "Search/{type}",
        new { controller = "Search", action = "Index" },
        new { type = searchTypes }
    )
    ...
&lt;/pre&gt;
&lt;br /&gt;
Very basic, all this does is enumerate through your enum and create a simple string to filter with.
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/RmtkYuiURPU4SDKhNCJTCSIXgOw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/RmtkYuiURPU4SDKhNCJTCSIXgOw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/RmtkYuiURPU4SDKhNCJTCSIXgOw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/RmtkYuiURPU4SDKhNCJTCSIXgOw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=9bLx8kKdke4:mVp8_ZofDlw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=9bLx8kKdke4:mVp8_ZofDlw:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=9bLx8kKdke4:mVp8_ZofDlw:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=9bLx8kKdke4:mVp8_ZofDlw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=9bLx8kKdke4:mVp8_ZofDlw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/9bLx8kKdke4" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/9bLx8kKdke4/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Constraining-Routes-in-MVC-to-an-Enum-the-Easy-Way.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=0271b592-bab0-45a9-95f6-85d2fd19ca2d</guid>
      <pubDate>Thu, 06 Oct 2011 17:40:00 -0500</pubDate>
      <category>asp.net</category>
      <category>c#</category>
      <category>mvc</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=0271b592-bab0-45a9-95f6-85d2fd19ca2d</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=0271b592-bab0-45a9-95f6-85d2fd19ca2d</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Constraining-Routes-in-MVC-to-an-Enum-the-Easy-Way.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=0271b592-bab0-45a9-95f6-85d2fd19ca2d</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=0271b592-bab0-45a9-95f6-85d2fd19ca2d</feedburner:origLink></item>
    <item>
      <title>Monitoring a DOM Element for Modification with jQuery</title>
      <description>&lt;h2&gt;'watching' an element for any change within it&lt;/h2&gt;
I recently ran into a situation where I had to modify a site that relied on an incredibly obfuscated and impossible to understand javascript file.  I had to add in some elements after everything was populated with some function I didn't get, so I had to wait until a specific element was populated to do anything.  Turns out the &lt;strong&gt;DOMNodeInserted&lt;/strong&gt; event is what I needed:
&lt;pre class="prettyprint"&gt;var title = $("b.facility");
var title = $('#title');//the element I want to monitor
title.bind('DOMNodeInserted', function(e) {
    alert('element now contains: ' + $(e.target).html());
});&lt;/pre&gt;
&lt;br /&gt;
Pretty simple, but took me forever to figure out...
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/LjHcEFWfwpl8lYNjHXnZlckZWHA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LjHcEFWfwpl8lYNjHXnZlckZWHA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/LjHcEFWfwpl8lYNjHXnZlckZWHA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LjHcEFWfwpl8lYNjHXnZlckZWHA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=CaJHGcA9iyc:mtiI6migGqM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=CaJHGcA9iyc:mtiI6migGqM:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=CaJHGcA9iyc:mtiI6migGqM:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=CaJHGcA9iyc:mtiI6migGqM:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=CaJHGcA9iyc:mtiI6migGqM:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/CaJHGcA9iyc" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/CaJHGcA9iyc/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Monitoring-a-DOM-Element-for-Modification-with-jQuery.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=eeb1306b-b316-480c-975d-da2851f07c2c</guid>
      <pubDate>Thu, 29 Sep 2011 16:47:00 -0500</pubDate>
      <category>javascript</category>
      <category>jquery</category>
      <category>steal some code</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=eeb1306b-b316-480c-975d-da2851f07c2c</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=eeb1306b-b316-480c-975d-da2851f07c2c</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Monitoring-a-DOM-Element-for-Modification-with-jQuery.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=eeb1306b-b316-480c-975d-da2851f07c2c</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=eeb1306b-b316-480c-975d-da2851f07c2c</feedburner:origLink></item>
    <item>
      <title>ReCaptcha - Getting the Challenge Key and/or image with Asp.Net MVC</title>
      <description>&lt;h2&gt;Often times you do not need the whole deal, or you are working with a technology that doesn't employ javascript or iframes&lt;/h2&gt;

Recently I was working on a project that needed to provide (via MVC 3) the ReCaptcha image and/or challenge key only, and not the whole html/javascript portion due to limitations by the data consumer.  It took me a while, but there is quite an elegant and simple solution to this.
&lt;br /&gt;&lt;br /&gt;
Here is the controller I came up with:
&lt;pre class="prettyprint"&gt;public class CaptchaController : Controller
{
    public string contentReturnType = "text/plain";
    public string googleChallengeUrl = "http://
        www.google.com/recaptcha/api/challenge?k={0}";
    public string googleImageUrl = "http://
        www.google.com/recaptcha/api/image?c={0}";
    public string googleImageHtml = "&amp;lt;img style=
        \"display: block; \" height=\"57\" width=\"300\" 
         src=\"{0}\"/&amp;gt;";

    [HttpGet]
    public ContentResult GetChallengeKey(
        string proxyIpAndPort = null)
    {
        string http = string.Format(googleChallengeUrl, 
            ReCaptchaValues.PublicKey);
        WebClient client = new WebClient();

        //assuming no proxy on a local machine
        if (!string.IsNullOrEmpty(proxyIpAndPort) &amp;&amp; 
            !Request.IsLocal) 
        {
            client.Proxy = 
                new WebProxy(proxyIpAndPort, true);
        }

        string html = client.DownloadString(http);
        int start = html.IndexOf('{');
        int length = html.IndexOf('}') - start + 1;
        string json = html.Substring(start, length);

        ReCaptchaState state = 
            new JavaScriptSerializer()
                .Deserialize&lt;ReCaptchaState&gt;(json);
        return this.Content(state.challenge, 
            contentReturnType);
    }

    [HttpGet]
    public ContentResult GetImageUrl()
    {
        return this.Content(string.Format(googleImageUrl, 
            GetChallengeKey().Content), contentReturnType);
    }

    [HttpGet]
    public ContentResult GetImageHtml()
    {
        return this.Content(string.Format(googleImageHtml, 
            GetImageUrl().Content), contentReturnType);
    }
}&lt;/pre&gt;
&lt;br /&gt;
This is using json deserializing of the ReCaptcha return string into a .Net object named ReCaptchaState which is covered here.&lt;br /&gt;&lt;br /&gt;
Now all that you need to do is call one of the urls to get the desired result in a plaintext format (you can change the output if you wish).
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/qLyOF9XFBhRHov4qh7Ek4s5zZMo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qLyOF9XFBhRHov4qh7Ek4s5zZMo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/qLyOF9XFBhRHov4qh7Ek4s5zZMo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qLyOF9XFBhRHov4qh7Ek4s5zZMo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=c0nG4fPn2NA:KcnIoEZR-s8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=c0nG4fPn2NA:KcnIoEZR-s8:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=c0nG4fPn2NA:KcnIoEZR-s8:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=c0nG4fPn2NA:KcnIoEZR-s8:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=c0nG4fPn2NA:KcnIoEZR-s8:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/c0nG4fPn2NA" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/c0nG4fPn2NA/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/ReCaptcha---Getting-the-Challenge-Key-andor-image-with-AspNet-MVC.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=94fc08ab-efc7-410c-9f0a-c9891c2ccc7a</guid>
      <pubDate>Mon, 01 Aug 2011 11:30:00 -0500</pubDate>
      <category>asp.net</category>
      <category>c#</category>
      <category>my projects</category>
      <category>steal some code</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=94fc08ab-efc7-410c-9f0a-c9891c2ccc7a</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=94fc08ab-efc7-410c-9f0a-c9891c2ccc7a</trackback:ping>
      <wfw:comment>http://naspinski.net/post/ReCaptcha---Getting-the-Challenge-Key-andor-image-with-AspNet-MVC.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=94fc08ab-efc7-410c-9f0a-c9891c2ccc7a</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=94fc08ab-efc7-410c-9f0a-c9891c2ccc7a</feedburner:origLink></item>
    <item>
      <title>Deserializing ReCaptcha JSON with C#</title>
      <description>&lt;h2&gt;Turning a ReCaptcha request into a strongly-typed C# object on the fly&lt;/h2&gt;

When requesting a ReCaptcha image, you send out this request:
&lt;blockquote&gt;http://www.google.com/recaptcha/api/challenge?k=your_public_key&lt;/blockquote&gt;
&lt;br /&gt;
You then receive this in return:
&lt;pre class="prettyprint"&gt;var RecaptchaState = {
    site : 'your_public_key',
    challenge : 'returned_challenge_key',
    is_incorrect : false,
    programming_error : '',
    error_message : '',
    server : 'http://www.google.com/recaptcha/api/',
    timeout : 18000
};

document.write('&amp;lt;scr'+'ipt type="text/javascript" 
    s'+'rc="' + RecaptchaState.server + 'js/recaptcha.js"&amp;gt;
    &amp;lt;/scr'+'ipt&amp;gt;');&lt;/pre&gt;
&lt;br /&gt;
Looking at that, you can pull the information you need into this object:
&lt;pre class="prettyprint"&gt;[Serializable]
public class ReCaptchaState
{
    [DataMember]
    public string site { get; set; }

    [DataMember]
    public string challenge { get; set; }

    [DataMember]
    public bool is_correct { get; set; }

    [DataMember]
    public string programming_error { get; set; }

    [DataMember]
    public string error_message { get; set; }

    [DataMember]
    public string server { get; set; }

    [DataMember]
    public int timeout { get; set; }
}&lt;/pre&gt;&lt;br /&gt;
By using this code:
&lt;pre class="prettyprint"&gt;WebClient client = new WebClient();
string ret = client.DownloadString(google_url);
int start = ret.IndexOf('{');
int length = ret.IndexOf('}') - start + 1;
string json = ret.Substring(start, length);

ReCaptchaState state = new JavaScriptSerializer()
    .Deserialize&amp;lt;ReCaptchaState&amp;gt;(json);&lt;/pre&gt;
&lt;br /&gt;
Now you have a &lt;strong&gt;ReCaptchaState&lt;/strong&gt; .net object you can use the values from; simple.
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/41kfVKq1vKWUBvg29Y--J0YO0Rg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/41kfVKq1vKWUBvg29Y--J0YO0Rg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/41kfVKq1vKWUBvg29Y--J0YO0Rg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/41kfVKq1vKWUBvg29Y--J0YO0Rg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=uc-izK4e_NQ:wAQmXl0uFwo:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=uc-izK4e_NQ:wAQmXl0uFwo:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=uc-izK4e_NQ:wAQmXl0uFwo:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=uc-izK4e_NQ:wAQmXl0uFwo:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=uc-izK4e_NQ:wAQmXl0uFwo:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/uc-izK4e_NQ" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/uc-izK4e_NQ/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Deserializing-ReCaptcha-JSON-with-C.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=3b60a44a-fcac-4085-8530-2b69b8e62ac1</guid>
      <pubDate>Mon, 01 Aug 2011 11:00:00 -0500</pubDate>
      <category>c#</category>
      <category>steal some code</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=3b60a44a-fcac-4085-8530-2b69b8e62ac1</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=3b60a44a-fcac-4085-8530-2b69b8e62ac1</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Deserializing-ReCaptcha-JSON-with-C.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=3b60a44a-fcac-4085-8530-2b69b8e62ac1</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=3b60a44a-fcac-4085-8530-2b69b8e62ac1</feedburner:origLink></item>
    <item>
      <title>CohesiveSoftware.com</title>
      <description>&lt;h2&gt;As I have been getting more and more freelance offers and work, the decision was made to launch a new website and brand&lt;/h2&gt;
Yesterday I launched &lt;a href="http://cohesivesoftware.com"&gt;CohesiveSoftware.com&lt;/a&gt; as a contact point for custom work. Me and some fellow developers have teamed up on a few projects and decided to make it official.  If you need any work done, please feel free to &lt;a href="http://cohesivesoftware.com/contact"&gt;drop us a line&lt;/a&gt; - happy coding!
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/UZ4jg8piKpjlAKMWh_XGkYmfFeU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UZ4jg8piKpjlAKMWh_XGkYmfFeU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/UZ4jg8piKpjlAKMWh_XGkYmfFeU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UZ4jg8piKpjlAKMWh_XGkYmfFeU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=8RP1tSAJqg4:OYTgB9eS0C0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=8RP1tSAJqg4:OYTgB9eS0C0:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=8RP1tSAJqg4:OYTgB9eS0C0:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=8RP1tSAJqg4:OYTgB9eS0C0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=8RP1tSAJqg4:OYTgB9eS0C0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/8RP1tSAJqg4" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/8RP1tSAJqg4/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/CohesiveSoftwarecom.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=d27c5653-4294-47cd-9bb7-78303be942ce</guid>
      <pubDate>Wed, 25 May 2011 14:20:00 -0500</pubDate>
      <category>my projects</category>
      <category>other</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=d27c5653-4294-47cd-9bb7-78303be942ce</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=d27c5653-4294-47cd-9bb7-78303be942ce</trackback:ping>
      <wfw:comment>http://naspinski.net/post/CohesiveSoftwarecom.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=d27c5653-4294-47cd-9bb7-78303be942ce</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=d27c5653-4294-47cd-9bb7-78303be942ce</feedburner:origLink></item>
    <item>
      <title>Updating Multiple Fields via LINQ and Reflection Automatically (EF4)</title>
      <description>&lt;h2&gt;You can use reflection to avoid manually entering a ton of fields&lt;/h2&gt;

Recently, the question was asked on &lt;a href="http://stackoverflow.com/questions/6089670/insert-into-all-columns-of-int-same-value/6089823#comment-7057622"&gt;Stackoverflow&lt;/a&gt; about updating multiple integer fields in an EF4 object without having to type each out manually.  I had run into a similar problem like this in the recent past where I had a large number of int fields (38 to be exact) and I didn't really want to write in 38 lines of essentially the same thing into my code.  Instead, I cam up with this using Reflection.  This simple example shows an object 'o' and a single new value 'newValue', but you can easily use an array or list as well for inserting values - this just gets the point across:

&lt;pre class="prettyprint"&gt;foreach(PropertyInfo prop in o.GetType().GetProperties()) 
{
    if(prop.PropertyType == typeof(int))
        prop.SetValue(o, newValue, null);
}&lt;/pre&gt;
&lt;br /&gt;
You can see in this example, I look only for integer fields, but it would be simple to check for any other type of field, or name, or a field that has a name that starts with 'abcd' - the list is endless and simple to adapt to.
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/a8dMzszIg9AYJULa44uEKPzCMsk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/a8dMzszIg9AYJULa44uEKPzCMsk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/a8dMzszIg9AYJULa44uEKPzCMsk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/a8dMzszIg9AYJULa44uEKPzCMsk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=AR_RwLMnQkE:ayX_uZEFNHk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=AR_RwLMnQkE:ayX_uZEFNHk:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=AR_RwLMnQkE:ayX_uZEFNHk:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=AR_RwLMnQkE:ayX_uZEFNHk:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=AR_RwLMnQkE:ayX_uZEFNHk:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/AR_RwLMnQkE" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/AR_RwLMnQkE/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Updating-Multiple-Fields-via-LINQ-and-Refelection-Automatically-(EF4).aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=733866b0-99ea-433c-b65c-5c4fedbfda4a</guid>
      <pubDate>Mon, 23 May 2011 16:00:00 -0500</pubDate>
      <category>c#</category>
      <category>entities</category>
      <category>linq</category>
      <category>linq-to-sql</category>
      <category>steal some code</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=733866b0-99ea-433c-b65c-5c4fedbfda4a</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=733866b0-99ea-433c-b65c-5c4fedbfda4a</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Updating-Multiple-Fields-via-LINQ-and-Refelection-Automatically-(EF4).aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=733866b0-99ea-433c-b65c-5c4fedbfda4a</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=733866b0-99ea-433c-b65c-5c4fedbfda4a</feedburner:origLink></item>
    <item>
      <title>Running C# libraries with the SQL CLR</title>
      <description>&lt;h2&gt;You can run your dlls from inside SQL - but it is a bit limited&lt;/h2&gt;
Sometimes you need your SQL server to run a little bit of one of your programs, this is not a common case, but I have found it does happen.  It is quite possible and not too complicated, but you are limited in what you can use.  For example, even in SQL 2008, the maximum framework you can run is 3.5 (really 2.0), so anything with 4.0 is off limits due to the CLR.  Also, many dlls are also off limits such as &lt;strong&gt;System.Data.Linq&lt;/strong&gt; and &lt;strong&gt;System.Data.Entity&lt;/strong&gt; so kiss most of your ORM solutions goodbye if you plan on doing this.
&lt;br /&gt;&lt;br /&gt;
For this example, I am going to use a simple table in my SQL which will follow after this.  For the example, I am going to write a C# method that writes in a new Widget to the Widgets table in the 'SqlClrTest' database at the current time - nothing fancy or useful, but it is easy to understand.
&lt;pre class="prettyprint lang-sql"&gt;CREATE TABLE Widget(
	Id INT NOT NULL IDENTITY PRIMARY KEY,
	Name NVARCHAR(100) NOT NULL,
	Created DATETIME NOT NULL
);&lt;/pre&gt;
&lt;br /&gt;
Now you need to set up your environment to handle the CLR:
&lt;pre class="prettyprint lang-sql"&gt;--allow you to use it
ALTER DATABASE SqlClrTest SET TRUSTWORTHY ON;

--and turn it on
sp_configure 'clr enabled', 1
GO
reconfigure
GO&lt;/pre&gt;
&lt;br /&gt;
Now in a new library, I will make a simple class with older ADO that inserts a new entry.  Yes, I know this isn't written well, but it is very simple to understand...
&lt;pre class="prettyprint"&gt;using System;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;

namespace SqlClr
{
    public class Widget
    {
        public Widget() { }

        [SqlProcedure]
        public static void Insert(SqlString name)
        {
            string connectionString = 
                "Data Source=.\\sqlexpress;
                 Initial Catalog=SqlClrTest;
                 Integrated Security=True";
            string date = SqlDateTime
                .Parse(DateTime.Now.ToString())
            SqlConnection conn = new 
                SqlConnection(connectionString);

            SqlCommand sqlComm = new 
                SqlCommand("INSERT INTO Widget 
                (Name, Created) VALUES 
                ('" + name.ToString() + "', '" + 
                date + "')", conn);

            conn.Open();
            sqlComm.ExecuteNonQuery();
            conn.Close();
        }
    }
}&lt;/pre&gt;
&lt;br/&gt;
Notice that the inputs are defined in &lt;strong&gt;System.Data.SqlType&lt;/strong&gt;, also, the method is painted with a &lt;strong&gt;[SqlProcedure]&lt;/strong&gt; attribute.  Now compile the dll and take down the path to it.  Go back into SQL and enter the following to compile the assembly into SQL:
&lt;pre class="prettyprint lang-sql"&gt;CREATE ASSEMBLY Sql_Clr
AUTHORIZATION dbo
FROM 'C:\path-to-assembly\SqlClr.dll'
WITH PERMISSION_SET = UNSAFE;&lt;/pre&gt;
&lt;br /&gt;
Now you will notice it shows up under your table &amp;gt; programmability &amp;gt; assemblies directory if it worked correctly. I gave it a name with an underscore so you can see where that comes into play later. Next you will need to make a stored procedure that calls the method:
&lt;pre class="prettyprint lang-sql"&gt;CREATE PROCEDURE WidgetInsert 
	@name nvarchar(100)
AS EXTERNAL 
	NAME Sql_Clr.[SqlClr.Widget].Insert;
GO&lt;/pre&gt;
&lt;br /&gt;
You can see that you call it in this format: &lt;strong&gt;SqlDllName[C#DllName].Method&lt;/strong&gt;.  Now all that is left is to call the method in SQL:
&lt;pre class="prettyprint lang-sql"&gt;EXEC WidgetInsert 'NEW WIDGET'&lt;/pre&gt;
&lt;br /&gt;
And you have successfully (in the most round-about way possible) used a SQL stored procedure to call a .Net dll to run a method to update the database.
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/w7U4h7kYiu63JiPqKGd0v5NaO-U/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/w7U4h7kYiu63JiPqKGd0v5NaO-U/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/w7U4h7kYiu63JiPqKGd0v5NaO-U/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/w7U4h7kYiu63JiPqKGd0v5NaO-U/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=cDfq5AWAEL4:cTDti7xai9E:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=cDfq5AWAEL4:cTDti7xai9E:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=cDfq5AWAEL4:cTDti7xai9E:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=cDfq5AWAEL4:cTDti7xai9E:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=cDfq5AWAEL4:cTDti7xai9E:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/cDfq5AWAEL4" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/cDfq5AWAEL4/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Running-C-libraries-with-the-SQL-CLR.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=52813931-a794-406a-9956-1e3cfc6f0a72</guid>
      <pubDate>Thu, 12 May 2011 16:04:00 -0500</pubDate>
      <category>c#</category>
      <category>sql</category>
      <category>steal some code</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=52813931-a794-406a-9956-1e3cfc6f0a72</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=52813931-a794-406a-9956-1e3cfc6f0a72</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Running-C-libraries-with-the-SQL-CLR.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=52813931-a794-406a-9956-1e3cfc6f0a72</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=52813931-a794-406a-9956-1e3cfc6f0a72</feedburner:origLink></item>
    <item>
      <title>Adding Custom Exception Handling Attributes to Your Asp.Net MVC Actions</title>
      <description>&lt;h2&gt;Attributes are a simple way to run common handling across many actions without repeating yourself&lt;/h2&gt;

I ran into a position where I was handling exceptions and pushing them to xml ContentResults the same way on multiple actions across many controller repeating a lot of code.  I was working on a REST interface that always was to return xml.  All Exception were to be returned in xml as well.  I found myself writing a lot of actions like this:

&lt;pre class="prettyprint"&gt;public ContentResult Fidget()
{
    try
    {
        //do a bunch of stuff
        //throw exceptions if I need to
    }
    catch(Exception ex) //now catch them and display xml
    {
        // turn the exception into xml
        return this.Content(myXmlException, "text/xml");
    }
    
    // if it made it here, return success xml
    return this.Content(successXml, "text/xml");
}&lt;/pre&gt;
&lt;br /&gt;
This worked great, but after a bunch of actions, the code was very redundant.  I want to handle exception the same on a lot of actions, but not all, so I decided to go to an &lt;strong&gt;Attribute&lt;/strong&gt;, specifically &lt;strong&gt;ActionFilterAttribute&lt;/strong&gt; and the &lt;strong&gt;IExceptionFilter&lt;/strong&gt;.  If I override the &lt;i&gt;OnException&lt;/i&gt;, I can automatically handle the Exceptions in the painted actions, so this is what I came up with:
&lt;pre class="prettyprint"&gt;[HttpGet]
public class XmlExceptionAttribute : 
    ActionFilterAttribute, IExceptionFilter
{
    public void OnException(ExceptionContext 
        filterContext)
    {
        if (filterContext.Exception == null) return;
        filterContext.ExceptionHandled = true;
        var response = filterContext.Controller
            .ControllerContext.HttpContext.Response;
        response.ContentType = "text/xml";
        response.Write((new Status(
            filterContext.Exception)).ToXmlString());
    }
}&lt;/pre&gt;
&lt;br /&gt;
*Note that the &lt;strong&gt;Status&lt;/strong&gt; object is a just an object I made to be serializeable and &lt;i&gt;.ToXmlString()&lt;/i&gt; is an &lt;a href="http://naspinski.net/post/Serializing-and-DeSerializing-XML-Objects-in-Net.aspx"&gt;extension method I came up with a while back to convert objects into xml strings on the fly&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;
Now, if the attribute is applied, all I have to do for the above behavior in an action is simply this:
&lt;pre class="prettyprint"&gt;[HttpGet]
[XmlException]
public ContentResult Fidget()
{
    //do a bunch of stuff, throw exceptions if I need to
    
    // if it made it here, return success xml
    return this.Content(successXml, "text/xml");
}&lt;/pre&gt;
&lt;br /&gt;
The behavior is now the EXACT same!
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/mge7GEgth6VVTFY8aBsZKiFs9JA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mge7GEgth6VVTFY8aBsZKiFs9JA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/mge7GEgth6VVTFY8aBsZKiFs9JA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mge7GEgth6VVTFY8aBsZKiFs9JA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=BK06kkVBLRU:UPHtVCyTRiQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=BK06kkVBLRU:UPHtVCyTRiQ:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=BK06kkVBLRU:UPHtVCyTRiQ:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=BK06kkVBLRU:UPHtVCyTRiQ:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=BK06kkVBLRU:UPHtVCyTRiQ:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/BK06kkVBLRU" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/BK06kkVBLRU/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Adding-Custom-Exception-Handling-Attributes-to-Your-AspNet-MVC-Actions.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=f0343123-83ca-4c90-abab-3bf73fa325b3</guid>
      <pubDate>Mon, 07 Mar 2011 12:00:00 -0500</pubDate>
      <category>c#</category>
      <category>mvc</category>
      <category>xml</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=f0343123-83ca-4c90-abab-3bf73fa325b3</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=f0343123-83ca-4c90-abab-3bf73fa325b3</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Adding-Custom-Exception-Handling-Attributes-to-Your-AspNet-MVC-Actions.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=f0343123-83ca-4c90-abab-3bf73fa325b3</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=f0343123-83ca-4c90-abab-3bf73fa325b3</feedburner:origLink></item>
    <item>
      <title>The argument types 'Edm.Decimal' and 'Edm.Double' are incompatible for this operation.</title>
      <description>&lt;h2&gt;error you may run into while making queries in Linq-to-Entities&lt;/h2&gt;
What this is indicating is that you are comparing a &lt;strong&gt;Decimal&lt;/strong&gt; data type to a number that is not a &lt;strong&gt;Decimal&lt;/strong&gt;.  While it may look like it, this:
&lt;pre class="prettyprint"&gt;0.007 // is *not* a double in .Net land

// the proper form is this:
0.007M&lt;/pre&gt;
&lt;br /&gt;
So instead of this query:
&lt;pre class="prettyprint"&gt;var query = db.aTable.Where("it.Length = 0.01");
// make sure it is this instead:
var query = db.aTable.Where("it.Length = 0.01M");&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/7lrA-hPSiobI_BdfRf30C4qVeC4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7lrA-hPSiobI_BdfRf30C4qVeC4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/7lrA-hPSiobI_BdfRf30C4qVeC4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7lrA-hPSiobI_BdfRf30C4qVeC4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=jI7P3Nx0czw:JqcENPyLUTY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=jI7P3Nx0czw:JqcENPyLUTY:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=jI7P3Nx0czw:JqcENPyLUTY:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=jI7P3Nx0czw:JqcENPyLUTY:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=jI7P3Nx0czw:JqcENPyLUTY:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/jI7P3Nx0czw" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/jI7P3Nx0czw/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/The-argument-types-EdmDecimal-and-EdmDouble-are-incompatible-for-this-operation.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=4cc0e163-c1e5-45e6-af05-5f2c5a5cf047</guid>
      <pubDate>Thu, 03 Mar 2011 20:40:00 -0500</pubDate>
      <category>c#</category>
      <category>entities</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=4cc0e163-c1e5-45e6-af05-5f2c5a5cf047</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=4cc0e163-c1e5-45e6-af05-5f2c5a5cf047</trackback:ping>
      <wfw:comment>http://naspinski.net/post/The-argument-types-EdmDecimal-and-EdmDouble-are-incompatible-for-this-operation.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=4cc0e163-c1e5-45e6-af05-5f2c5a5cf047</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=4cc0e163-c1e5-45e6-af05-5f2c5a5cf047</feedburner:origLink></item>
    <item>
      <title>Serializing and DeSerializing XML Objects in .Net</title>
      <description>&lt;h2&gt;these two simple extension methods with have you switching between XML and objects in no time&lt;/h2&gt;

First off, it is pretty well known that if you have any Object and want to convert it into an XML strong, you can use the &lt;strong&gt;XmlSerializer&lt;/strong&gt; to do so.  I encapsulated the process is a simple extension method that run from any object - this will work as long as the object has a constructor with no inputs (ie: new SomeObject()) as that is the constraint passed up from &lt;strong&gt;XmlSerializer&lt;/strong&gt;.  Here is the method for converting from an object to an xml string:

&lt;pre class="prettyprint"&gt;public static string ToXmlString(this Object o)
{
    StringWriter xml = new 
        StringWriter(new StringBuilder());
    XmlSerializer xS = new XmlSerializer(o.GetType());
    xS.Serialize(xml, o);
    return xml.ToString();
}&lt;/pre&gt;
&lt;br /&gt;
With this, now all you need to do is:
&lt;pre class="prettyprint"&gt;MyObject obj = new MyObject();
// a bunch of stuff here...
// now I want the xml representation of this:
string xml = obj.ToXmlString();&lt;/pre&gt;
&lt;br /&gt;
Now to go backwards, you can use the similar &lt;strong&gt;Deserialize&lt;/strong&gt; along with the &lt;string&gt;XmlSerializer&lt;/strong&gt; with this method:

&lt;pre class="prettyprint"&gt;public static T XmlToObject&amp;lt;T&amp;gt;(this string s)
{
    var xR = XmlReader.Create(new 
        StringReader(s));
    XmlSerializer xS = new XmlSerializer(typeof(T)); 
    T obj = (T)xS.Deserialize(xR);
    return obj;
}&lt;/pre&gt;
&lt;br /&gt;
It is important to notice that this is taking in a raw xml string, which would not be web safe.  If you were taking in data from a web source, you would want to employ &lt;strong&gt;HttpUtility.UrlDecode(s)&lt;/strong&gt; instead of just &lt;strong&gt;s&lt;/strong&gt; above.
Now if you want to turn your above string 'xml' into an object again, simply call it like this:
&lt;pre class="prettyprint"&gt;MyObject obj2 = xml.XmlToObject&amp;lt;SomeObject&amp;gt;();&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/sgbaNGSHYDVsFwIBidTMtwKI-a8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/sgbaNGSHYDVsFwIBidTMtwKI-a8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/sgbaNGSHYDVsFwIBidTMtwKI-a8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/sgbaNGSHYDVsFwIBidTMtwKI-a8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=VU7DBwnbH2s:sGYZON1vYMk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=VU7DBwnbH2s:sGYZON1vYMk:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=VU7DBwnbH2s:sGYZON1vYMk:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=VU7DBwnbH2s:sGYZON1vYMk:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=VU7DBwnbH2s:sGYZON1vYMk:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/VU7DBwnbH2s" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/VU7DBwnbH2s/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Serializing-and-DeSerializing-XML-Objects-in-Net.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=05fcfd89-d331-438f-8802-d3068fe7876d</guid>
      <pubDate>Tue, 01 Mar 2011 00:50:00 -0500</pubDate>
      <category>c#</category>
      <category>steal some code</category>
      <category>xml</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=05fcfd89-d331-438f-8802-d3068fe7876d</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=05fcfd89-d331-438f-8802-d3068fe7876d</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Serializing-and-DeSerializing-XML-Objects-in-Net.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=05fcfd89-d331-438f-8802-d3068fe7876d</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=05fcfd89-d331-438f-8802-d3068fe7876d</feedburner:origLink></item>
  </channel>
</rss>

