<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>The MossyBlog Times Archives 2007 - 2009 : LINQ</title><link>http://blogs.msdn.com/msmossyblog/archive/tags/LINQ/default.aspx</link><description>Tags: LINQ</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>LINQ to SQL – Poormans DAO / CRUD.</title><link>http://blogs.msdn.com/msmossyblog/archive/2009/01/11/linq-to-sql-poormans-dao-crud.aspx</link><pubDate>Sun, 11 Jan 2009 11:26:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9305533</guid><dc:creator>scbarnes</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/msmossyblog/comments/9305533.aspx</comments><wfw:commentRss>http://blogs.msdn.com/msmossyblog/commentrss.aspx?PostID=9305533</wfw:commentRss><wfw:comment>http://blogs.msdn.com/msmossyblog/rsscomments.aspx?PostID=9305533</wfw:comment><description>&lt;p&gt;I’m an extremely lazy coder. If i can find a way to write a base class to do the bulk of my chores within code, by crikey I'll do it and damn the scorn from my peers.&lt;/p&gt;  &lt;p&gt;In this case, I wanted to write fairly generic CRUD (Create, Read, Update &amp;amp; Delete) methods using LINQ to SQL. The rationale as to why I wanted to do this was simply due to the fact that LINQ to SQL already takes care of writing the various Entity Classes properties – so - &lt;em&gt;why do I still need to tease out each field name to do an Update or Select?&lt;/em&gt; &lt;/p&gt;  &lt;p&gt;The other reason I came up with this as I had some issues with UPDATE in LINQ to SQL (mainly due to having relational tables), basically i was breaking the “&lt;a href="http://martinfowler.com/eaaCatalog/unitOfWork.html" target="_blank"&gt;unit of work&lt;/a&gt;” pattern and blaming LINQ to SQL for not doing what I thought its job should be&lt;em&gt; (I'm sure I'll bend the ear of the LINQ team on what I think the right approach should be hehe).&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Here is my cheat source on how to get out of actually doing work.&lt;/p&gt;  &lt;h2&gt;The BaseDAO.&lt;/h2&gt;  &lt;p&gt;This class is where you’ll inherit all your DAO classes from here on out (should you buy into my code wisdom). I’ve kept the methods as generic as possible and the tax you pay for doing this is that the execution time will grow by a few ms (my tests found it not noticeable).&lt;/p&gt;  &lt;p&gt;When firing your &lt;strong&gt;Update, Create, Delete&lt;/strong&gt; &amp;amp; &lt;strong&gt;Read&lt;/strong&gt; methods, you simply pass in your proposed entity to persist as well as the &lt;strong&gt;DataContext&lt;/strong&gt; in which you wish to use. I’m not thrilled at passing &lt;strong&gt;DataContexts&lt;/strong&gt; around in arguments but in this case I couldn’t think of an alternative approach.&lt;/p&gt;  &lt;pre style="border-right: #cecece 1px solid; padding-right: 5px; border-top: #cecece 1px solid; padding-left: 5px; min-height: 40px; padding-bottom: 5px; overflow: auto; border-left: #cecece 1px solid; width: 433px; padding-top: 5px; border-bottom: #cecece 1px solid; height: 281px; background-color: #fbfbfb"&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  1: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;  2: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Data.Linq;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  3: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Data.Linq.Mapping;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;  4: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Linq;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  5: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Reflection;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;  6: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  7: &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; JARVIS.Lib.DAL
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;  8: {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  9:     &lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 10:     &lt;span style="color: #808080"&gt;/// Base Data Access Object&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 11:     &lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 12:     &lt;span style="color: #808080"&gt;/// &amp;lt;remarks&amp;gt;TODO:&amp;lt;/remarks&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 13:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; BaseDAO
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 14:     {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 15:         &lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 16:         &lt;span style="color: #808080"&gt;/// Update an Entity Row in the LINQ Context.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 17:         &lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 18:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; T Update&amp;lt;T&amp;gt;(T entity, DataContext db) where T : &lt;span style="color: #0000ff"&gt;class&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 19:         {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 20:             &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (db)
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 21:             {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 22:                 Table&amp;lt;T&amp;gt; table = db.GetTable&amp;lt;T&amp;gt;();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 23:                 T original = table.FirstOrDefault(e =&amp;gt; e == entity);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 24:                 &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (original != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 25:                 {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 26:                     var model = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; AttributeMappingSource().GetModel(db.GetType());
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 27:                     MetaTable tbl = model.GetTable(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(T));
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 28:                     &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (var dm &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; tbl.RowType.DataMembers)
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 29:                     {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 30:                         PropertyInfo p1 = original.GetType().GetProperty(dm.MappedName);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 31:                         PropertyInfo p2 = entity.GetType().GetProperty(dm.MappedName);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 32:                         &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 33:                         {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 34:                             &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (p1.PropertyType.ToString() != &amp;quot;&lt;span style="color: #8b0000"&gt;System.DateTime&lt;/span&gt;&amp;quot;)
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 35:                             {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 36:                                 p1.SetValue(original, p2.GetValue(entity, &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;), &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 37:                             }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 38:                             &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 39:                             {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 40:                                 &lt;span style="color: #008000"&gt;// *** WARNING: Cheesy Hack : WARNING ***&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 41:                                 &lt;span style="color: #008000"&gt;//                                &lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 42:                                 &lt;span style="color: #008000"&gt;// Just in case you have a row that doesn't have DateTime Set..&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 43:                                 &lt;span style="color: #008000"&gt;// This will hack your way past an exception. Highly recommend&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 44:                                 &lt;span style="color: #008000"&gt;// you ensure your data going into the DB is validated against&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 45:                                 &lt;span style="color: #008000"&gt;// DB rules.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 46:                                 &lt;span style="color: #008000"&gt;//&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 47:                                 &lt;span style="color: #008000"&gt;// No, i'm not proud of this but meh.. great code happens when you ship v3 :D&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 48:                                 &lt;span style="color: #008000"&gt;//&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 49:                                 &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; dtStr = p2.GetValue(entity, &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;).ToString();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 50:                                 DateTime dt = Convert.ToDateTime(dtStr);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 51:                                 System.Diagnostics.Trace.WriteLine(dt.Year);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 52:                                 &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (dt.Year &amp;gt; 1)
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 53:                                 {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 54:                                     p1.SetValue(original, p2.GetValue(entity, &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;), &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 55:                                 }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 56:                             }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 57:                         }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 58:                         &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 59:                         {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 60:                             System.Diagnostics.Trace.WriteLine(dm.MappedName);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 61:                         }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 62:                     }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 63:                 }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 64:                 db.SubmitChanges();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 65:                 db.Dispose();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 66:                 &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; original;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 67:             }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 68:         }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 69: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 70:         &lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 71:         &lt;span style="color: #808080"&gt;/// Create an Entity Row into the LINQ Context&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 72:         &lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 73:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; T Create&amp;lt;T&amp;gt;(T entity, DataContext db) where T : &lt;span style="color: #0000ff"&gt;class&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 74:         {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 75:             &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (db)
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 76:             {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 77:                 Table&amp;lt;T&amp;gt; table = db.GetTable&amp;lt;T&amp;gt;();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 78:                 table.InsertOnSubmit(entity);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 79:                 db.SubmitChanges();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 80:             }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 81:             db.Dispose();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 82:             &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; entity;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 83:         }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 84: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 85:         &lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 86:         &lt;span style="color: #808080"&gt;/// Read an Entity Row from the LINQ context back (based of Primary Key setting)&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 87:         &lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 88:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; T Read&amp;lt;T&amp;gt;(T entity, DataContext db) where T : &lt;span style="color: #0000ff"&gt;class&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 89:         {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 90:             &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (db)
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 91:             {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 92:                 Table&amp;lt;T&amp;gt; table = db.GetTable&amp;lt;T&amp;gt;();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 93:                 T original = table.FirstOrDefault(e =&amp;gt; e == entity);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 94:                 db.Dispose();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 95:                 &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; original;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 96:             }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 97:         }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 98: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 99:         &lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;100:         &lt;span style="color: #808080"&gt;/// Hard Delete a Row from the LINQ Context. Note, this will DELETE from the database, its recommended you Retire records not Delete them.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;101:         &lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;102:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; HardDelete&amp;lt;T&amp;gt;(T entity, DataContext db) where T : &lt;span style="color: #0000ff"&gt;class&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;103:         {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;104:             &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (db)
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;105:             {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;106:                 Table&amp;lt;T&amp;gt; table = db.GetTable&amp;lt;T&amp;gt;();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;107:                 T original = table.FirstOrDefault(e =&amp;gt; e == entity);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;108:                 &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (original != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;109:                 {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;110:                     table.DeleteOnSubmit(original);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;111:                     db.SubmitChanges();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;112:                 }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;113:             }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;114:             db.Dispose();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;115:         }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;116:     }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;117: }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;118: &lt;/pre&gt;&lt;/pre&gt;

&lt;h2&gt;The UserDAO.&lt;/h2&gt;

&lt;pre style="border-right: #cecece 1px solid; padding-right: 5px; border-top: #cecece 1px solid; padding-left: 5px; min-height: 40px; padding-bottom: 5px; overflow: auto; border-left: #cecece 1px solid; width: 433px; padding-top: 5px; border-bottom: #cecece 1px solid; height: 250px; background-color: #fbfbfb"&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  1: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;  2: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Data.Linq;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  3: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Linq;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;  4: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; JARVIS.Models.Security.TO;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  5: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Reflection;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;  6: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Data.Linq.Mapping;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  7: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; JARVIS.Lib.DAL;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;  8: &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; JARVIS.Models.Security.DAO
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  9: {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 10:     &lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 11:     &lt;span style="color: #808080"&gt;/// JARVIS.User Data Access Object&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 12:     &lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 13:     &lt;span style="color: #808080"&gt;/// &amp;lt;remarks&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 14:     &lt;span style="color: #808080"&gt;/// TODO: &lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 15:     &lt;span style="color: #808080"&gt;/// - Add Triggers for Realtional Data (ie Users Roles etc) for Delete  Method&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 16:     &lt;span style="color: #808080"&gt;/// &amp;lt;/remarks&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 17:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; UserDAO : BaseDAO
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 18:     {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 19:         &lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 20:         &lt;span style="color: #808080"&gt;/// Update a UserTO from the Persistance Layer based off the UserId&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 21:         &lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 22:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; T Update&amp;lt;T&amp;gt;(T entityTO) where T : UserTO
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 23:         {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 24: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 25:             var db = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; JARVISDBDataContext();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 26:             JARVIS_User entity = entityTO.ConvertToLINQ(entityTO);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 27:             entity.ModifiedDate = DateTime.Now;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 28:             JARVIS_User updated = &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.Update(entity, db) &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; JARVIS_User;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 29:             T result = entityTO.ConvertToTO(updated) &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; T;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 30:             &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; result;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 31:         }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 32: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 33:         &lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 34:         &lt;span style="color: #808080"&gt;/// Retire a UserTO from the Persistance Layer based off the UserId&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 35:         &lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 36:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; T Delete&amp;lt;T&amp;gt;(T entityTO) where T : UserTO
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 37:         {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 38:             var db = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; JARVISDBDataContext();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 39:             JARVIS_User entity = entityTO.ConvertToLINQ(entityTO);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 40: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 41:             &lt;span style="color: #008000"&gt;// TimeStamp the UserTO Modification Dates and Mark for Retirement.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 42:             entity.ModifiedDate = DateTime.Now;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 43:             entity.IsRetired = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 44: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 45:             &lt;span style="color: #008000"&gt;// Return a Modified UserTO&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 46:             JARVIS_User updated = &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.Update(entity, db) &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; JARVIS_User;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 47:             T result = entityTO.ConvertToTO(updated) &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; T;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 48:             &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; result;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 49:         }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 50: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 51:         &lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 52:         &lt;span style="color: #808080"&gt;/// Create a UserTO into the Persistance Layer&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 53:         &lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 54:         &lt;span style="color: #808080"&gt;/// &amp;lt;returns&amp;gt;An updated UserTO&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 55:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; T Create&amp;lt;T&amp;gt;(T entityTO) where T : UserTO
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 56:         {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 57: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 58:             var db = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; JARVISDBDataContext();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 59:             JARVIS_User entity = entityTO.ConvertToLINQ(entityTO);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 60: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 61:             &lt;span style="color: #008000"&gt;// Modify the Timestamps.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 62:             entity.CreatedDate = DateTime.Now;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 63:             entity.ModifiedDate = DateTime.Now;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 64:             &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.Create(entity, db);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 65:             T result = entityTO &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; T;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 66:             &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; result;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 67:         }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 68: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 69:         &lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 70:         &lt;span style="color: #808080"&gt;/// Return a UserTO from the Persistance Layer based off the UserId&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 71:         &lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 72:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; T Read&amp;lt;T&amp;gt;(T entityTO) where T : UserTO
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 73:         {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 74:             var db = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; JARVISDBDataContext();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 75:             JARVIS_User entity = entityTO.ConvertToLINQ(entityTO);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 76:             JARVIS_User updated = &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.Read(entity, db);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 77:             T result = entityTO.ConvertToTO(updated) &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; T;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 78:             &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; result;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 79:         }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 80:     }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 81: }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 82: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;As you can see, fairly simplified approach from here on out, essentially what I’ll do here is simply map the &lt;strong&gt;T&lt;/strong&gt; to the appropriate Type and ensure I go between my Transfer Object type to the LINQ type and back again, always ensuring the code beyond &lt;strong&gt;UserDAO&lt;/strong&gt; really has no clue as to what flavor of LINQ I'm using.&lt;/p&gt;

&lt;h2&gt;The UserTO.&lt;/h2&gt;

&lt;p&gt;I’m a bit of a fan of &lt;a href="http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html" target="_blank"&gt;Transfer Objects&lt;/a&gt;, but again, I’m lazy and well the correct thing to do here would be to NOT inherit the LINQ table &lt;strong&gt;JARVIS_User&lt;/strong&gt;, but since the fields are already there and I hate typing, its “meh” to any whom object.&lt;/p&gt;

&lt;pre style="border-right: #cecece 1px solid; padding-right: 5px; border-top: #cecece 1px solid; padding-left: 5px; min-height: 40px; padding-bottom: 5px; overflow: auto; border-left: #cecece 1px solid; width: 430px; padding-top: 5px; border-bottom: #cecece 1px solid; height: 253px; background-color: #fbfbfb"&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  1: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Data.Linq.Mapping;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;  2: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Reflection;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  3: &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; JARVIS.Models.Security.TO
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;  4: {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  5:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; UserTO : JARVIS_User
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;  6:     {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  7: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;  8: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  9:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; UserTO ConvertToTO(JARVIS_User userTO)
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 10:         {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 11:             var context = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; JARVISDBDataContext();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 12:             var model = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; AttributeMappingSource().GetModel(context.GetType());
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 13:             UserTO instance = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UserTO();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 14:             MetaTable tbl = model.GetTable(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(JARVIS_User));
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 15:             &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (var dm &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; tbl.RowType.DataMembers)
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 16:             {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 17:                 &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 18:                 {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 19:                     PropertyInfo p1 = instance.GetType().GetProperty(dm.MappedName);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 20:                     PropertyInfo p2 = userTO.GetType().GetProperty(dm.MappedName);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 21:                     p1.SetValue(instance, p2.GetValue(userTO, &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;), &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 22:                 }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 23:                 &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 24:                 {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 25:                 }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 26:             }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 27:             context.Dispose();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 28:             &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; instance;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 29:         }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 30: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 31: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 32:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; JARVIS_User ConvertToLINQ(UserTO userTO)
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 33:         {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 34:             var context = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; JARVISDBDataContext();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 35:             var model = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; AttributeMappingSource().GetModel(context.GetType());
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 36:             JARVIS_User instance = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; JARVIS_User();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 37:             MetaTable tbl = model.GetTable(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(JARVIS_User));
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 38:             &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (var dm &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; tbl.RowType.DataMembers)
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 39:             {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 40:                 &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 41:                 {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 42:                     PropertyInfo p1 = instance.GetType().GetProperty(dm.MappedName);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 43:                     PropertyInfo p2 = userTO.GetType().GetProperty(dm.MappedName);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 44:                     p1.SetValue(instance, p2.GetValue(userTO, &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;), &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 45:                     &lt;span style="color: #008000"&gt;//System.Diagnostics.Trace.WriteLine(p1.GetValue(instance,null));&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 46:                 }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 47:                 &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 48:                 {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 49:                 }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 50:             }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 51:             context.Dispose();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 52:             &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; instance;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 53:         }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 54:     }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 55: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 56: }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 57: &lt;/pre&gt;&lt;/pre&gt;

&lt;h2&gt;The Test.&lt;/h2&gt;

&lt;p&gt;In this Test, It simply shows the various routines being fired within context to all of the above.&lt;/p&gt;

&lt;pre style="border-right: #cecece 1px solid; padding-right: 5px; border-top: #cecece 1px solid; padding-left: 5px; min-height: 40px; padding-bottom: 5px; overflow: auto; border-left: #cecece 1px solid; width: 436px; padding-top: 5px; border-bottom: #cecece 1px solid; height: 365px; background-color: #fbfbfb"&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  1: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;  2: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; JARVIS.Models.Security.DAO;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  3: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; JARVIS.Models.Security.TO;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;  4: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; Microsoft.VisualStudio.TestTools.UnitTesting;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  5: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;  6: &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; JARVIS.Tests.Controllers
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  7: {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt;  8:     &lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  9:     &lt;span style="color: #808080"&gt;/// Summary description for SecurityController&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 10:     &lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 11:     [TestClass]
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 12:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; SecurityController
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 13:     {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 14:         [TestMethod]
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 15:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; UserAccountTest()
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 16:         {
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 17: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 18:             &lt;span style="color: #008000"&gt;// DAO&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 19:             UserDAO dao = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UserDAO();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 20: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 21:             &lt;span style="color: #008000"&gt;// User Entity.            &lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 22:             UserTO userTO = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UserTO();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 23:             &lt;span style="color: #008000"&gt;//userTO.UserId = new Guid(&amp;quot;e47dcd57-4c91-4118-b9c5-027de0270620&amp;quot;);&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 24:             userTO.UserId = Guid.NewGuid();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 25:             userTO.Username = &amp;quot;&lt;span style="color: #8b0000"&gt;scbarnes&lt;/span&gt;&amp;quot;;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 26:             userTO.Password = &amp;quot;&lt;span style="color: #8b0000"&gt;itsasecret&lt;/span&gt;&amp;quot;;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 27:             userTO.DisplayName = &amp;quot;&lt;span style="color: #8b0000"&gt;None&lt;/span&gt;&amp;quot;;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 28:             userTO.Email = &amp;quot;&lt;span style="color: #8b0000"&gt;&lt;/span&gt;&amp;quot;;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 29:             userTO.IsActive = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 30:             userTO.CreatedBy = userTO.UserId;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 31:             userTO.ModifiedBy = userTO.UserId;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 32: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 33:             &lt;span style="color: #008000"&gt;// CREATE&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 34:             UserTO o1 = dao.Create(userTO);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 35: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 36:             &lt;span style="color: #008000"&gt;// UPDATE            &lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 37:             userTO.Username = &amp;quot;&lt;span style="color: #8b0000"&gt;UsernameUpdated&lt;/span&gt;&amp;quot;;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 38:             UserTO o2 = dao.Update(userTO);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 39: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 40:             &lt;span style="color: #008000"&gt;// DELETE&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 41:             dao.Delete(userTO);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 42: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 43:             &lt;span style="color: #008000"&gt;// READ&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 44:             UserTO o3 = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UserTO();
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 45:             o3.UserId = o2.UserId;
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 46:             UserTO o4 = dao.Read(o3);
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 47: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 48:         }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 49: 
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 50:     }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; 51: }
&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #ffffff"&gt; 52: &lt;/pre&gt;&lt;/pre&gt;

&lt;h2&gt;The Versions Used..&lt;/h2&gt;

&lt;p&gt;I’m currently using the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=A24D1E00-CD35-4F66-BAA0-2362BDDE0766&amp;amp;displaylang=en" target="_blank"&gt;ASP.NET MVC Beta&lt;/a&gt; which was released on 10/15/2008.&amp;#160; (.NET 3.5).&lt;/p&gt;

&lt;h2&gt;The End.&lt;/h2&gt;

&lt;p&gt;Look, I’m not saying its “champagne C#” and I’m sure it will ruffle a few feathers of some dire hard pattern fans, but at the end of the day, I’ve put in enough layers of abstraction here to allow for trouble to be stomped out. In the event the above becomes to taxing on the server loads, it’s easily swapped in / out from the DAO level down, and that in itself is the true power of object orientated programming.&lt;/p&gt;

&lt;p&gt;Will it win me the Martin Fowler award of excellence, probably not, but hey, I’m shipping :)&lt;/p&gt;

&lt;p&gt;Scott Out.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9305533" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/MVC/default.aspx">MVC</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/.NET/default.aspx">.NET</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/Design+Patterns/default.aspx">Design Patterns</category></item><item><title>My code just went SubSonic.</title><link>http://blogs.msdn.com/msmossyblog/archive/2007/08/05/my-code-just-went-subsonic.aspx</link><pubDate>Sun, 05 Aug 2007 11:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4238897</guid><dc:creator>scbarnes</dc:creator><slash:comments>11</slash:comments><comments>http://blogs.msdn.com/msmossyblog/comments/4238897.aspx</comments><wfw:commentRss>http://blogs.msdn.com/msmossyblog/commentrss.aspx?PostID=4238897</wfw:commentRss><wfw:comment>http://blogs.msdn.com/msmossyblog/rsscomments.aspx?PostID=4238897</wfw:comment><description>&lt;P&gt;I absolutely love the the goodness which is &lt;A href="http://www.subsonicproject.com/" target=_blank mce_href="http://www.subsonicproject.com/"&gt;SubSonic 2.0.3&lt;/A&gt; (2.0.4 on it's way). It's basically a way of automating most of your mundane day to day Database tasks (CRUD - Create, Read, Update, Delete) by using it in a form of native objects.&lt;/P&gt;
&lt;P&gt;Example time:&lt;/P&gt;&lt;PRE&gt;        NxsFINExpense ExpenseClaim = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; NxsFINExpense();
        ExpenseClaim.Amount = Convert.ToDecimal( dtbleResult.Rows[0][1] );
        ExpenseClaim.Description = dtbleResult.Rows[0][2].ToString();
        ExpenseClaim.ReceiptDate = Convert.ToDateTime(dtbleResult.Rows[0][0]);
        &lt;FONT color=#ff0000&gt;ExpenseClaim.Save();&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;Basically there is a table in my Database called "&lt;STRONG&gt;nxsFIN_Expenses&lt;/STRONG&gt;" and each of the properties found on the &lt;STRONG&gt;ExpenseClaim&lt;/STRONG&gt; Class is in fact a field within the table (respective type setting also associated via Convert casting).&lt;/P&gt;
&lt;P&gt;The part that I love the most is "&lt;FONT color=#ff0000&gt;ExpenseClaim.Save()&lt;/FONT&gt;" which pretty much kills all efforts to writing the "INSERT INTO" bloated SQL Query. This is the kind of magic I've come to embrace inside the .NET community in that, basically everyone's just as lazy as me and would prefer to focus on hard-logic instead of basic CRUD's for example.&lt;/P&gt;
&lt;P&gt;I have to say, in the my old&amp;nbsp;Coldfusion circle's we really didn't have anything this automated. I think the closest I've seen probably is "&lt;A href="http://corfield.org/blog/index.cfm/do/blog.entry/entry/ModelGlue_Unity__Video_Demo" target=_blank mce_href="http://corfield.org/blog/index.cfm/do/blog.entry/entry/ModelGlue_Unity__Video_Demo"&gt;Model-Glue: Unity&lt;/A&gt;"&amp;nbsp;&amp;nbsp;Framework apparently when I last spoke to &lt;A href="http://corfield.org/blog/index.cfm/do/blog.entry/entry/ModelGlue_Unity__Video_Demo" target=_blank mce_href="http://corfield.org/blog/index.cfm/do/blog.entry/entry/ModelGlue_Unity__Video_Demo"&gt;Sean&lt;/A&gt; about it, he stated it cained Ruby-on-Rails (Sean's wise and if he says it did, well I'll assume it did!). &lt;/P&gt;
&lt;P&gt;Combine SubSonic with &lt;A href="http://msdn.microsoft.com/vstudio/" target=_blank mce_href="http://msdn.microsoft.com/vstudio/"&gt;Visual Studio 2008&lt;/A&gt;, &lt;A href="http://www.microsoft.com/sql/editions/express/default.mspx" target=_blank mce_href="http://www.microsoft.com/sql/editions/express/default.mspx"&gt;SQL Express&lt;/A&gt; and overall I have a nice warm fuzzy glowing feeling about my progress so far. Whom knows, with this &lt;STRONG&gt;ExpenseClaim .NET&lt;/STRONG&gt; application I'm writing I may even get my expenses lodged in-time from here on out.&lt;/P&gt;
&lt;P&gt;All thanks to &lt;A href="http://www.subsonicproject.com/" target=_blank mce_href="http://www.subsonicproject.com/"&gt;SubSonic's&lt;/A&gt; productivity gains (did I oversell that?)&lt;/P&gt;
&lt;P&gt;Points to note:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;So far my entire development environment is costing &lt;STRONG&gt;&lt;U&gt;$0&lt;/U&gt;&lt;/STRONG&gt; (i.e assuming I didn't work for Microsoft).&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://subsonicproject.com/view/setting-up-your-webappconfig.aspx" target=_blank mce_href="http://subsonicproject.com/view/setting-up-your-webappconfig.aspx"&gt;SubSonic&lt;/A&gt; has some minor issues, like you have to update the &lt;STRONG&gt;&lt;A href="http://subsonicproject.com/view/setting-up-your-webappconfig.aspx" target=_blank mce_href="http://subsonicproject.com/view/setting-up-your-webappconfig.aspx"&gt;Builder.abp&lt;/A&gt;&lt;/STRONG&gt; file every time you make a database change (to ensure that the framework reflects the database appropriately. I had Namespace errors when I didn't do this).&lt;/LI&gt;
&lt;LI&gt;You need to pay attention to the "&lt;A href="http://subsonicproject.com/view/setting-up-your-webappconfig.aspx" target=_blank mce_href="http://subsonicproject.com/view/setting-up-your-webappconfig.aspx"&gt;Getting Started&lt;/A&gt;" videos, as it can be a bit of a pain to setup.&lt;/LI&gt;
&lt;LI&gt;I'm guessing with complex Database(s) things could get a bit un-nerving (feel free to shoot this point down as I'm not locked into that belief).&lt;/LI&gt;
&lt;LI&gt;LINQ + SubSonic appear to play well with one another, so I'll explore this at a later date.&lt;/LI&gt;
&lt;LI&gt;It has a really cool trick (this will get it the ladies). In that it will take a plural (Categories) and rename it to (Category) when dealing with singular references (ie ActiveRecord). Doesn't that make you feel gooey inside, reading this? damn straight.&lt;/LI&gt;
&lt;LI&gt;I think SubSonic and I should kiss, you know.. to break the tension.. (Simpsons Movie fans will relate to that joke heh).&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Next.. bolting on the Silverlight GUI.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4238897" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/SubSonic/default.aspx">SubSonic</category></item></channel></rss>