<?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:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-1934426700208076473</atom:id><lastBuildDate>Fri, 10 Feb 2012 21:18:02 +0000</lastBuildDate><category>Visual Studio</category><category>Business Layer</category><category>Comma Separated Values</category><category>Stored Procedure</category><category>Membership</category><category>Forms Authentication</category><category>DetailsView</category><category>MasterPage</category><category>MetadataType</category><category>MSTest</category><category>Roles</category><category>Text</category><category>Text File</category><category>Visual Studio 2008</category><category>SPAN</category><category>Profile</category><category>SqlServer</category><category>Find / Replace</category><category>ClientScript</category><category>UpdatePanel</category><category>JScript</category><category>LINQDataSource</category><category>Keys</category><category>Custom Attributes</category><category>PMP</category><category>GridView</category><category>Interfaces</category><category>Data Access Layer</category><category>DateTime</category><category>Agile</category><category>Attach</category><category>Object expected</category><category>Areas</category><category>Internet Explorer</category><category>Visual Source Safe</category><category>Internal Members</category><category>DropDownList</category><category>JavaScript</category><category>Label</category><category>Vista</category><category>MVC</category><category>Postback</category><category>Cache</category><category>Code Smells</category><category>Primary Key</category><category>Compress</category><category>Navigation</category><category>Authorization</category><category>Scroll Position</category><category>Security</category><category>Parse</category><category>Ajax</category><category>TimeStamp</category><category>Checkbox</category><category>KVM</category><category>Version</category><category>SQL Server Management Studio</category><category>Xml</category><category>Function</category><category>App.Config</category><category>KSOD</category><category>uml</category><category>Steelers</category><category>StoredProcedure</category><category>Asp.net</category><category>Textbox</category><category>ConnectionString</category><category>Unit Testing</category><category>Design Patterns</category><category>ListView</category><category>Code First</category><category>Menu</category><category>Group By</category><category>T-SQL Scripts</category><category>EntityFramework</category><category>Design Smells</category><category>ContentPage</category><category>RegEx</category><category>CSV</category><category>Generics</category><category>VB</category><category>FormView</category><category>Groups</category><category>C#</category><category>Web.Config</category><category>jquery</category><category>web interface</category><category>ModelBinder</category><category>ScriptManager</category><category>Database</category><category>Div</category><category>DataAnnotations</category><category>Validation</category><category>IE</category><category>Regular Expression</category><category>Password</category><category>Repository Pattern</category><category>LINQ To SQL</category><category>Silverlight</category><title>Paul Brown</title><description>Musings and ramblings on .Net, Steelers, and other Stuff.</description><link>http://pretzelsteelersfan.blogspot.com/</link><managingEditor>noreply@blogger.com (PretzelSteelersFan)</managingEditor><generator>Blogger</generator><openSearch:totalResults>74</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/PaulBrown" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="paulbrown" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-7294590301807838891</guid><pubDate>Mon, 21 Nov 2011 19:10:00 +0000</pubDate><atom:updated>2011-11-21T13:10:59.281-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Regular Expression</category><category domain="http://www.blogger.com/atom/ns#">DataAnnotations</category><category domain="http://www.blogger.com/atom/ns#">RegEx</category><title>Diffference Between RegEx.IsMatch and the RegularExpressionAttribute</title><description>&lt;p&gt;I was working on some code that stores a month as CCYYMM string. Of course I wanted to validate the string with Regex so I had the pattern&lt;/p&gt;  &lt;pre&gt;^20[0-2][0-9](0[1-9])|(1[0-2])$&lt;/pre&gt;

&lt;p&gt;Everything was fine as long as I was using Regex.IsMatch. The problems started when I used the RegularExpressionAttribute. Suddenly, I was getting errors everywhere. I constructed a little test to verify that there was a difference. What I found was that using the same string and pattern, yielded different results.&lt;/p&gt;

&lt;p&gt;Here’s my unit test.&lt;/p&gt;

&lt;pre&gt;[TestMethod]
public void DifferenceBetweenIsMatchAndRegExAttribute()
{
  var pattern = &amp;quot;^20[0-2][0-9](0[1-9])|(1[0-2])$&amp;quot;;
  int cnt = 0;
  var months = new string[]
  {
  &amp;quot;201001&amp;quot;,
  &amp;quot;201002&amp;quot;,
  &amp;quot;201003&amp;quot;,
  &amp;quot;201004&amp;quot;,
  &amp;quot;201005&amp;quot;,
  &amp;quot;201006&amp;quot;,
  &amp;quot;201007&amp;quot;,
  &amp;quot;201008&amp;quot;,
  &amp;quot;201009&amp;quot;,
  &amp;quot;201010&amp;quot;,
  &amp;quot;201011&amp;quot;,
  &amp;quot;201012&amp;quot; };&lt;/pre&gt;

&lt;pre&gt;  var attribute = new RegularExpressionAttribute(pattern);
  bool isMatchOk = false;
  bool isAttrOk = false;
 
  foreach (var month in months)
  {
    isMatchOk = System.Text.RegularExpressions.Regex.IsMatch(month, pattern);
    isAttrOk = attribute.IsValid(month);
 
    if (isMatchOk &amp;amp; isAttrOk)
    { cnt += 1; }
  }
 
  Assert.AreEqual(12, cnt);
}&lt;/pre&gt;

&lt;p&gt;You would expect the number of matches to be 12 but it’s actually 9. Why? Because the attribute is matching only the first half of our pattern. It stops at the pipe (|). To prove this, I flipped the sides of the pipe and got 3. If I add parens around both sides of the logical &lt;em&gt;or &lt;/em&gt;I will get the answer I’m looking for.&lt;/p&gt;

&lt;p&gt;^20[0-2][0-9]((0[1-9])|(1[0-2]))$ &lt;/p&gt;

&lt;p&gt;While it seems logical that the RegularExpressionAttribute would use Regex.IsMatch underneath, it apparently is not the case. I’m betting the reason has to do with JavaScript compatibility. Remember, the attribute must also validate client side.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-7294590301807838891?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2011/11/i-was-working-on-some-code-that-stores.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-7186894268728895907</guid><pubDate>Tue, 26 Apr 2011 19:05:00 +0000</pubDate><atom:updated>2011-04-26T14:09:59.362-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Code First</category><category domain="http://www.blogger.com/atom/ns#">SqlServer</category><category domain="http://www.blogger.com/atom/ns#">EntityFramework</category><title>Updated Code To Get Class Definition From Table Structure</title><description>&lt;p&gt;My previous post on &lt;a href="http://pretzelsteelersfan.blogspot.com/2010/06/script-to-create-metadatatype-classes.html" target="_blank"&gt;Script to Create MetadataType classes&lt;/a&gt; was to work with LINQ-To-SQL and partial classes. EF 4.1 introduces Code First which uses POCOs and here is the code to create a class definition from a table’s structure.&lt;/p&gt;  &lt;p&gt;Enjoy.&lt;/p&gt;  &lt;pre class="brush: sql;"&gt;SET NOCOUNT ON
declare @TableName varchar(256) = 'BusinessTypes'
declare @EntityName varchar(256) = 'BusinessType'
declare @TableSchema varchar(256) = 'dbo'

declare @ColumnName varchar(256)
    , @DataType varchar(256)
    , @NewDataType varchar(256)
    , @MaxLength int
    , @Nullable varchar(5)
    
declare @Lines table (Line varchar(1000))

insert into @Lines select 'public class ' + @EntityName
insert into @Lines select '{'

declare @DataTypes table (SqlDataType varchar(1000), DataType varchar(1000))

insert into @DataTypes (SqlDataType, DataType) values ('bit', 'bool')
insert into @DataTypes (SqlDataType, DataType) values ('char', 'string')
insert into @DataTypes (SqlDataType, DataType) values ('datetime', 'DateTime')
insert into @DataTypes (SqlDataType, DataType) values ('decimal', 'decimal')
insert into @DataTypes (SqlDataType, DataType) values ('int', 'int')
insert into @DataTypes (SqlDataType, DataType) values ('money', 'decimal')
insert into @DataTypes (SqlDataType, DataType) values ('ntext', 'string')
insert into @DataTypes (SqlDataType, DataType) values ('nvarchar', 'string')
insert into @DataTypes (SqlDataType, DataType) values ('smalldatetime', 'DateTime')
insert into @DataTypes (SqlDataType, DataType) values ('timestamp', 'byte[]')
insert into @DataTypes (SqlDataType, DataType) values ('uniqueidentifier', 'Guid')
insert into @DataTypes (SqlDataType, DataType) values ('varchar', 'string')

declare cols cursor for 
    select COLUMN_NAME, Data_type, CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE
    from INFORMATION_SCHEMA.COLUMNS
    where table_Name = @TableName and table_schema = @Tableschema
    order by ORDINAL_POSITION

open cols

fetch next from cols into  @ColumnName, @DataType, @MaxLength, @Nullable
while @@FETCH_STATUS = 0
begin
    select @NewDataType = DataType from @DataTypes where SqlDataType = @DataType
    
    if @DataType in ('varchar', 'char') and @Nullable = 'NO'
        insert into @Lines select char(9) + '[Required]'
        
    if @DataType in ('varchar', 'char')
        insert into @Lines select char(9) + '[StringLength(' + CAST(@MaxLength as varchar) + ')]'
    
    insert into @Lines select char(9) + 'public ' + @NewDataType + ' ' + @ColumnName + ' { get; set; }'
    
    insert into @Lines select char(9) + ''
    
    fetch next from cols into  @ColumnName, @DataType, @MaxLength, @Nullable
end

close cols
deallocate cols
insert into @Lines select '}'

select * FROM @Lines

SET NOCOUNT OFF&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-7186894268728895907?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2011/04/updated-code-to-get-class-definition.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-2822318034934842384</guid><pubDate>Tue, 01 Mar 2011 15:02:00 +0000</pubDate><atom:updated>2011-03-01T09:02:46.586-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Unit Testing</category><category domain="http://www.blogger.com/atom/ns#">MSTest</category><title>Replacement for ExpectedException in MS Test</title><description>&lt;p&gt;This &lt;a href="http://stackoverflow.com/questions/1944774/in-mstest-how-can-i-verify-exact-error-message-using-expectedexceptiontypeofa" target="_blank"&gt;StackOverflow thread&lt;/a&gt; has a great solution for the issue that ExpectedException does not allow you to validate the error message. Look at the response from winSharp93 and the ExceptionAssert class. This is a much cleaner method and also shows some great ways to use generics.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-2822318034934842384?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2011/03/replacement-for-expectedexception-in-ms.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-2560972825612254297</guid><pubDate>Fri, 18 Feb 2011 16:50:00 +0000</pubDate><atom:updated>2011-02-18T10:51:12.361-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">uml</category><category domain="http://www.blogger.com/atom/ns#">SqlServer</category><title>Script To Grab Column Names As UML Properties</title><description>&lt;p&gt;I was cooking up some UML diagrams for an existing DB and wanted to get all of the properties. It lists the table, column name in UML markup format and then the data type. The data type column is there so that all I have to do is order it by the second column and I’ll get all of the nulls so I can see if I’m getting a data type that I haven’t handled. The data type conversion is by no means complete but it’s a good start.&lt;/p&gt;&lt;p&gt;Enjoy!&lt;/p&gt;&lt;pre class="brush: sql;"&gt;select table_name, '+ ' + column_name + ' : ' +
    CASE WHEN DATA_TYPE in ('ntext', 'nvarchar', 'varchar', 'char') then 'string'
        WHEN DATA_TYPE = 'bit' then 'bool'
        WHEN DATA_TYPE = 'int' then 'int'
        WHEN DATA_TYPE = 'timestamp' then 'timestamp'
        WHEN DATA_TYPE = 'uniqueidentifier' then 'Guid'
        WHEN DATA_TYPE = 'money' then 'decimal'
        WHEN DATA_TYPE in ('smalldatetime', 'datetime') then 'datetime'
        END,
    DATA_TYPE
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME not like '%aspnet%'
    and TABLE_NAME &amp;lt;&amp;gt; 'sysdiagrams'
order by 1, 2&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-2560972825612254297?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2011/02/script-to-grab-column-names-as-uml.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-5746289781715370085</guid><pubDate>Mon, 10 Jan 2011 15:14:00 +0000</pubDate><atom:updated>2011-01-10T09:14:03.494-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Stored Procedure</category><category domain="http://www.blogger.com/atom/ns#">SqlServer</category><category domain="http://www.blogger.com/atom/ns#">Function</category><category domain="http://www.blogger.com/atom/ns#">Database</category><category domain="http://www.blogger.com/atom/ns#">StoredProcedure</category><title>SQL To Find String In Procedure/Function</title><description>&lt;p&gt;I do a lot of work updating legacy systems. Almost every system needs the column names updated since the names are usually short and not very descriptive. Here’s a command for finding all store procedures/functions that use a specified column.&lt;/p&gt;  &lt;pre class="brush: sql;"&gt;select s.name, a.name FROM sys.sql_modules m
inner join sys.all_objects a on m.object_id = a.object_id
inner join sys.schemas s on a.schema_id = s.schema_id
where m.definition like '%MyColumnName%'&lt;/pre&gt;

&lt;p&gt;INFORMATION_SCHEMA.ROUTINES is unreliable because it is limited to the first 4000 characters.&lt;/p&gt;

&lt;p&gt;Enjoy!!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-5746289781715370085?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2011/01/sql-to-find-string-in-procedurefunction.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-4931359304570398410</guid><pubDate>Mon, 03 Jan 2011 15:49:00 +0000</pubDate><atom:updated>2011-01-03T09:49:22.611-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SqlServer</category><category domain="http://www.blogger.com/atom/ns#">Xml</category><title>Read XML File Into SQL Server</title><description>&lt;p&gt;Wayne Sheffield has a nice article on reading XML files into sql. &lt;a href="http://www.sqlservercentral.com/articles/XML/71659/" target="_blank"&gt;You can find it here.&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-4931359304570398410?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2011/01/read-xml-file-into-sql-server.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-6820534086158310202</guid><pubDate>Thu, 28 Oct 2010 15:08:00 +0000</pubDate><atom:updated>2010-10-28T10:08:21.688-05:00</atom:updated><title>User Story Screen</title><description>&lt;p&gt;The user story screen is the starting point for all work. It tells a story from the user perspective that we can use to determine what work needs to be done. This story should be short so that the work can be done in a couple of days. More complicated stories should be broken up into smaller stories so the work can be broken into pieces. My rule of thumb is if the story is takes more than a paragraph or so, you need to break it up.&lt;/p&gt;  &lt;p&gt;Here’s the User Story screen from VS.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_6SIaqZS_bz4/TMmR4pBjgJI/AAAAAAAAAG0/7BoFobayBiE/s1600-h/User%20Story%5B2%5D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="User Story" border="0" alt="User Story" src="http://lh4.ggpht.com/_6SIaqZS_bz4/TMmR5BiWBvI/AAAAAAAAAG4/UweyGVgt1nc/User%20Story_thumb.png?imgmax=800" width="244" height="162" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Title&lt;/strong&gt; – A one sentence description of the story.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Assigned&lt;/strong&gt; &lt;strong&gt;To&lt;/strong&gt; – The single individual responsible for the story.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;State&lt;/strong&gt; – Indicates the current state of the story.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Active – The story is currently being worked on or waiting to be worked on.&lt;/li&gt;    &lt;li&gt;Closed – The story was closed without being resolved.&lt;/li&gt;    &lt;li&gt;Resolved – The story was completed and implemented.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;Reason&lt;/strong&gt; – The reason the item is in the current state. Matching states are in parenthesis.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;New – A new story (Active).&lt;/li&gt;    &lt;li&gt;Abandoned – The story was no longer relevant (Closed).&amp;#160; &lt;/li&gt;    &lt;li&gt;Out Of Scope – The story does not fall within the scope of the current project (Closed).&lt;/li&gt;    &lt;li&gt;Rejected – The story was not desired by management, too complex or violates system integrity (Closed).&lt;/li&gt;    &lt;li&gt;Code complete and unit tests pass – Work has been completed and all unit tests pass (Resolved).&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;Area&lt;/strong&gt; – The functional area of the application such as clients, services, etc.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Iteration&lt;/strong&gt; – The iteration of the system where the task will be worked on. This may correspond to sprints but it could be version number based. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Stack&lt;/strong&gt; &lt;strong&gt;Rank&lt;/strong&gt; – The relative importance of the item to the product owner(s).&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;System/process &lt;b&gt;&lt;u&gt;must&lt;/u&gt;&lt;/b&gt; support this user story / functionality&lt;/li&gt;    &lt;li&gt;System/process &lt;b&gt;&lt;u&gt;should&lt;/u&gt;&lt;/b&gt; support this user story / functionality&lt;/li&gt;    &lt;li&gt;System/process &lt;b&gt;&lt;u&gt;could&lt;/u&gt;&lt;/b&gt; support this user story / functionality&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;strong&gt;Story&lt;/strong&gt; &lt;strong&gt;Points&lt;/strong&gt; – An indicator of the complexity of the user story. This value allows for comparison between stories based on an abstract value rather than time (which is not the same between developers).&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Risk&lt;/strong&gt; – The level of risk to the project if the item is not completed.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-6820534086158310202?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2010/10/user-story-screen.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/_6SIaqZS_bz4/TMmR5BiWBvI/AAAAAAAAAG4/UweyGVgt1nc/s72-c/User%20Story_thumb.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-2907265348154252926</guid><pubDate>Thu, 28 Oct 2010 14:34:00 +0000</pubDate><atom:updated>2010-10-28T10:10:02.262-05:00</atom:updated><title>A Simple Man’s Guide To Using VS &amp; TFS 2010</title><description>&lt;p&gt;One of the areas I personally struggle with is planning and organizing. I’m a doer. Git-r-dun! I can see a task and wiz through coding it. As long as I’m the only developer, this works great. When you’re the team lead, it’s not a good thing. What ends up happening is that everything is in your head. The team doesn’t know what to work on and the users don’t know the status of the project. &lt;/p&gt;  &lt;p&gt;Want to know if you’re in this category? Take a day off and see what happens! If you come back and find that things have gone haywire, welcome to the club. &lt;/p&gt;  &lt;p&gt;So what’s the solution? For me, learning Agile and Scrum basics and using VS/TFS 2010 to keep track of stuff. For the next several posts, I ‘m going to document how we’re going to use VS/TFS 2010. If you’ve done it differently, please let me know. I’ll update this post as the master to keep track of everything together.&lt;/p&gt;  &lt;p&gt;The first step will be to create a user story for each discrete activity. Then we’ll write the test cases that insure things are working correctly. Finally, we’ll create the tasks for the actual coding. The following links cover each of the items in VS/TFS 2010 and how we’ll be using them.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://pretzelsteelersfan.blogspot.com/2010/10/user-story-screen.html"&gt;User Story&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Test Case&lt;/p&gt;  &lt;p&gt;Task&lt;/p&gt;  &lt;p&gt;Bug&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-2907265348154252926?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2010/10/simple-mans-guide-to-using-vs-tfs-2010.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-8770106502279646266</guid><pubDate>Mon, 28 Jun 2010 20:13:00 +0000</pubDate><atom:updated>2010-06-28T15:13:06.568-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Unit Testing</category><category domain="http://www.blogger.com/atom/ns#">SqlServer</category><title>Quick Script to Create Constants from All Columns Names</title><description>&lt;p&gt;One thing I like to do in all my apps is create a static class that holds constants for all Column/Property names. This just avoids messing up names in places where I need to use strings. This is particularly useful when checking that attributes have been applied.&lt;/p&gt;  &lt;pre class="brush: sql;"&gt;select 
     'public const string ' + COLUMN_NAME + ' = &amp;quot;' + COLUMN_NAME + '&amp;quot;;'
from INFORMATION_SCHEMA.COLUMNS
where table_Name in ('Agencies', 'Customers')
group by COLUMN_NAME
order by COLUMN_NAME&lt;/pre&gt;

&lt;p&gt;The code produced looks like this:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;public static class ColumnNames
{
    public const string AgencyName = &amp;quot;AgencyName&amp;quot;;
    public const string CustomerName = &amp;quot;CustomerName&amp;quot;;
}&lt;/pre&gt;

&lt;p&gt;I can then refer to the name using something like&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;VerifyPropertyHasAttribute(ColumnName.AgencyName, typeof(RequiredAttribute));&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-8770106502279646266?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2010/06/quick-script-to-create-constants-from.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-515923034064050970</guid><pubDate>Mon, 28 Jun 2010 20:03:00 +0000</pubDate><atom:updated>2011-04-26T14:08:49.740-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Custom Attributes</category><category domain="http://www.blogger.com/atom/ns#">SqlServer</category><category domain="http://www.blogger.com/atom/ns#">LINQ To SQL</category><category domain="http://www.blogger.com/atom/ns#">MetadataType</category><title>Script to Create MetadataType classes</title><description>&lt;p&gt;&lt;span style="color: red;"&gt;UPDATE: &lt;/span&gt;Here's the same thing for &lt;a href="http://pretzelsteelersfan.blogspot.com/2011/04/updated-code-to-get-class-definition.html"&gt;EF 4.1 and Code First.&lt;/a&gt;&lt;br /&gt;
&lt;p&gt;&lt;p&gt;I’ve been using the DataAnnotations for a validation with MVC2 and Silverlight 4. They both rely on metadata (buddy) classes. The Entity Framework now will create metaclasses for you but LinqToSql didn’t get this feature.&lt;/p&gt;&lt;p&gt;This short script will create a partial class and a metaclass for the specified table. &lt;/p&gt;&lt;p&gt;&amp;#160;&lt;/p&gt;&lt;pre class="brush: sql;"&gt;declare @TableName varchar(256) = 'Agencies'
declare @EntityName varchar(256) = 'Agency'
declare @TableSchema varchar(256) = 'dbo'

declare @ColumnName varchar(256)
    , @DataType varchar(256)
    , @MaxLength int
    , @Nullable varchar(5)
    
declare @Lines table (Line varchar(1000))

insert into @Lines select 'partial class ' + @EntityName
insert into @Lines select '{'
insert into @Lines select '}'
insert into @Lines select 'public class ' + @EntityName + 'MetaClass'
insert into @Lines select '{'

declare cols cursor for 
    select COLUMN_NAME, Data_type, CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE
    from INFORMATION_SCHEMA.COLUMNS
    where table_Name = @TableName and table_schema = @Tableschema
    order by ORDINAL_POSITION

open cols

fetch next from cols into  @ColumnName, @DataType, @MaxLength, @Nullable
while @@FETCH_STATUS = 0
begin
    if @DataType in ('varchar', 'char') and @Nullable = 'NO'
        insert into @Lines select char(9) + '[Required]'
        
    if @DataType in ('varchar', 'char')
        insert into @Lines select char(9) + '[StringLength(' + CAST(@MaxLength as varchar) + ')]'
    
    insert into @Lines select char(9) + 'public object ' + @ColumnName + ' { get; set; }'
    
    insert into @Lines select char(9) + ''
    
    fetch next from cols into  @ColumnName, @DataType, @MaxLength, @Nullable
end

close cols
deallocate cols
insert into @Lines select '}'

select * FROM @Lines&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-515923034064050970?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2010/06/script-to-create-metadatatype-classes.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-571341753666021646</guid><pubDate>Tue, 11 May 2010 14:58:00 +0000</pubDate><atom:updated>2010-05-11T09:58:21.892-05:00</atom:updated><title>Picture for Dell Tech</title><description>&lt;p&gt;   &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_6SIaqZS_bz4/S-lwiqStUfI/AAAAAAAAAGM/EyOvd8HypnM/s1600-h/image%5B2%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_6SIaqZS_bz4/S-lwjL0Wh7I/AAAAAAAAAGQ/6ME8wlF8JP8/image_thumb.png?imgmax=800" width="244" height="213" /&gt;&lt;/a&gt; &lt;a href="http://www.jpmstyle.com/gadget/dell-studio-xps-435-core-i7-desktop/"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-571341753666021646?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2010/05/picture-for-dell-tech.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/_6SIaqZS_bz4/S-lwjL0Wh7I/AAAAAAAAAGQ/6ME8wlF8JP8/s72-c/image_thumb.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-2139864909323798309</guid><pubDate>Sun, 04 Apr 2010 03:19:00 +0000</pubDate><atom:updated>2010-04-03T22:19:43.583-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">MVC</category><category domain="http://www.blogger.com/atom/ns#">Asp.net</category><category domain="http://www.blogger.com/atom/ns#">ModelBinder</category><title>Breaking? Change In Asp.Net MVC2</title><description>&lt;p&gt;In MVC1, by default an empty textbox was sent as string.Empty to the controller on POST. In MVC2, it now sends the value as NULL. See &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.modelmetadata.convertemptystringtonull(VS.100).aspx"&gt;ModelMetadata.ConvertEmptyStringToNull&lt;/a&gt;. I think there are some valid reasons for why they made the change – see &lt;a href="http://forums.asp.net/t/1522119.aspx"&gt;Brad Wilson’s comment&lt;/a&gt; for more. If your system relies on string.Empty, you’ve got a problem. &lt;/p&gt;  &lt;p&gt;There are several options for handling this. The first is using the DisplayFormatAttribute on every property that needs it. Painful. Here’s an example:&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;[DisplayFormat(ConvertEmptyStringToNull=false)]
public string FirstName { get; set; }&lt;/pre&gt;

&lt;p&gt;You can also write a custom binder that sets this value to false. Like so:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;public class CustomStringModelBinder : DefaultModelBinder 
{
    public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {

        var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);   
        if (bindingContext.ModelType == typeof(string))
        {   
            bindingContext.ModelMetadata.ConvertEmptyStringToNull = false;
            if (value == null || string.IsNullOrEmpty(value.AttemptedValue))   
                return &amp;quot;&amp;quot;;
        }
        return value.AttemptedValue;
    }
}&lt;/pre&gt;

&lt;p&gt;You’ll need to add the following to the Global.asax Application_Start method to use your custom model binder.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;ModelBinders.Binders.Add(typeof(string), new CustomStringModelBinder());&lt;/pre&gt;

&lt;p&gt;One thing to note, if you use the RequiredAttribute, you don’t need to worry about the null because it will invalidate the model based on the NULL.&lt;/p&gt;

&lt;p&gt;Which option is better? Neither. Simply pick the default for ConvertEmptyStringToNull and then use DisplayFormat to handle the exceptions. Not perfect but not bad.&lt;/p&gt;

&lt;p&gt;I do wish that this was configurable in some way instead of creating a ModelBinder.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-2139864909323798309?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2010/04/breaking-change-in-aspnet-mvc2.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-8919559855283248078</guid><pubDate>Thu, 01 Apr 2010 12:54:00 +0000</pubDate><atom:updated>2010-04-01T07:59:01.284-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">MVC</category><category domain="http://www.blogger.com/atom/ns#">Navigation</category><category domain="http://www.blogger.com/atom/ns#">Areas</category><title>Navigation Using Areas in Asp.Net MVC</title><description>&lt;p&gt;Asp.Net MVC2 introduced Areas as a feature part of the framework. Areas allow you to divide your application into logical units. It also makes your Url’s look more accurate. &lt;/p&gt;  &lt;p&gt;Thinking of a generic store they might have areas such as Inventory, Payroll, Employees and Sales. Here are example ActionLinks for each area.&lt;/p&gt;  &lt;pre class="brush: xml;"&gt;&amp;lt;%= Html.ActionLink(&amp;quot;Home&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Home&amp;quot;, new { area = &amp;quot;&amp;quot; }, new { })%&amp;gt;
&amp;lt;%= Html.ActionLink(&amp;quot;Payroll&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Main&amp;quot;, new { area = &amp;quot;Payroll&amp;quot; }, new { })%&amp;gt;
&amp;lt;%= Html.ActionLink(&amp;quot;Inventory&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Main&amp;quot;, new { area = &amp;quot;Inventory&amp;quot; }, new { })%&amp;gt;
&amp;lt;%= Html.ActionLink(&amp;quot;Employees&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Main&amp;quot;, new { area = &amp;quot;Employees&amp;quot; }, new { })%&amp;gt;
&amp;lt;%= Html.ActionLink(&amp;quot;Sales&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Main&amp;quot;, new { area = &amp;quot;Sales&amp;quot; }, new { })%&amp;gt;&lt;/pre&gt;

&lt;p&gt;Notice that the area is passed as a route value. I wrote my own overload for the ActionLink that takes the Area as an argument.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;public static MvcHtmlString ActionLink(this HtmlHelper helper, string linkText, string actionName, string controllerName, string areaName, object routeValues, object htmlAttributes)
{
    RouteValueDictionary routes = new RouteValueDictionary(routeValues);
    RouteValueDictionary attributes = new RouteValueDictionary(htmlAttributes);
    routes.Add(&amp;quot;area&amp;quot;, areaName);
    return helper.ActionLink(linkText, actionName, controllerName, routes, attributes);
}&lt;/pre&gt;

&lt;p&gt;This makes our links look as follows:&lt;/p&gt;

&lt;pre class="brush: xml;"&gt;&amp;lt;%= Html.ActionLink(&amp;quot;Home&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Home&amp;quot;, &amp;quot;&amp;quot;, new { }, new { })%&amp;gt;
&amp;lt;%= Html.ActionLink(&amp;quot;Payroll&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Main&amp;quot;, &amp;quot;Payroll&amp;quot;, new { }, new { })%&amp;gt;
&amp;lt;%= Html.ActionLink(&amp;quot;Inventory&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Main&amp;quot;, &amp;quot;Inventory&amp;quot;, new { }, new { })%&amp;gt;
&amp;lt;%= Html.ActionLink(&amp;quot;Employees&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Main&amp;quot;, &amp;quot;Employees&amp;quot;, new { }, new { })%&amp;gt;
&amp;lt;%= Html.ActionLink(&amp;quot;Sales&amp;quot;, &amp;quot;Index&amp;quot;, &amp;quot;Main&amp;quot;, &amp;quot;Sales&amp;quot;, new { }, new { })%&amp;gt;&lt;/pre&gt;

&lt;p&gt;If you haven’t worked with Areas yet, your probably looking at the routes and noticing that each area link has a controller called Main with an Index method. You might think we’re calling the same controller and passing the area name as parameter. That is not what we are doing, each area has a controller named Main. Maybe the generated links will help.&lt;/p&gt;

&lt;pre class="brush: xml;"&gt;http://somedomain.com/Payroll/Main&lt;br /&gt;
http://somedomain.com/Inventory/Main&lt;br /&gt;
http://somedomain.com/Employees/Main&lt;br /&gt;
http://somedomain.com/Sales/Main&lt;/pre&gt;

&lt;p&gt;Next thing you should notice is that the link for returning to the Home page has an empty area. We need this so that when we’re in an area we can move back up to the root. Otherwise, we’ll get a Resource Not Found error indicating showing that it’s looking for Home in that Area. This can also work in your favor. If you have a Home controller (or Main) in all of your areas, MVC will, by default, navigate within the Area and you don’t need to change your Site.Master.&lt;/p&gt;

&lt;p&gt;Overall, areas are a great feature for keeping your applications organized. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-8919559855283248078?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2010/04/navigation-using-areas-in-aspnet-mvc.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-7081001713598582253</guid><pubDate>Fri, 19 Mar 2010 17:53:00 +0000</pubDate><atom:updated>2010-03-19T12:53:00.702-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><title>Lose your Find / Replace window?</title><description>&lt;p&gt;Working in VS2010, I suddenly lost my Find /Replace window. I found this &lt;a href="http://www.west-wind.com/Weblog/ShowPost.aspx?id=713402"&gt;post&lt;/a&gt; from Rick Strahl but unfortunately that doesn’t work for me since ALT-M is mapped as a menu shortcut.&lt;/p&gt;  &lt;p&gt;Solution: Window –&amp;gt; Dock.&lt;/p&gt;  &lt;p&gt;This will dock the window and then you can move it to your desired location.&lt;/p&gt;  &lt;p&gt;Cheers!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-7081001713598582253?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2010/03/lose-your-find-replace-window.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-622098851190363264</guid><pubDate>Fri, 12 Mar 2010 17:09:00 +0000</pubDate><atom:updated>2010-03-12T11:46:29.621-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Regular Expression</category><category domain="http://www.blogger.com/atom/ns#">Find / Replace</category><category domain="http://www.blogger.com/atom/ns#">SQL Server Management Studio</category><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><title>Visual Studio/SQL Server Management Studio Find and Replace with Regular Expressions</title><description>&lt;p&gt;I needed to format a bunch of strings in SQL Management Studio (this works for VS also) and finally took the time to figure out Find/Replace with Regular Expressions. &lt;/p&gt;  &lt;p&gt;The first thing to note is that VS/SSMS use different regex codes (don’t know why but I’m sure they have their reasons). You can find the list of codes &lt;a href="http://msdn.microsoft.com/en-us/library/2k3te2cs(VS.100).aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;I have list of 3 strings containing 10 digits followed by a space and then 3 letters. I wanted to replace the digits with the word Descriptor.&lt;/p&gt;  &lt;p&gt;Here’s my data:&lt;/p&gt;  &lt;pre&gt;1234567870 ABC
1234567880 DEF
1234567890 GHI&lt;/pre&gt;

&lt;p&gt;Here’s my find expression:&lt;/p&gt;

&lt;pre&gt;[0-9]^10 {[A-Z]^3}&lt;/pre&gt;

&lt;p&gt;Here’s my replace expression:&lt;/p&gt;

&lt;pre&gt;Descriptor: \1&lt;/pre&gt;

&lt;p&gt;Here’s my result:&lt;/p&gt;

&lt;pre&gt;Descriptor: ABC
Descriptor: DEF
Descriptor: GHI&lt;/pre&gt;

&lt;p&gt;The key is the {} brackets and \1. The {} brackets tell the engine I want to keep whatever matches the expression. This is called a Tagged Expression. The \1 says place the first tagged expression here. I can create multiple tagged expressions and place by using \1, \2, etc. I can even change the order in the result because they are numbered based on their order in the original expression. You can use newlines (\n) so that you can break lines apart). &lt;/p&gt;

&lt;p&gt;This is great for creating some testing stuff or moving non-standard data.&lt;/p&gt;

&lt;p&gt;Sweet!&lt;/p&gt;

&lt;div class="blogger-post-footer"&gt;&lt;a title="Subscribe to my feed" href="http://feeds.feedburner.com/PaulBrown" type="application/rss+xml" rel="alternate"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" alt="" src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" /&gt;&lt;/a&gt;&lt;a title="Subscribe to my feed" href="http://feeds.feedburner.com/PaulBrown" type="application/rss+xml" rel="alternate"&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-622098851190363264?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2010/03/visual-studiosql-server-management.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-8299217314330605238</guid><pubDate>Tue, 22 Dec 2009 16:00:00 +0000</pubDate><atom:updated>2009-12-22T10:00:23.215-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">MVC</category><category domain="http://www.blogger.com/atom/ns#">Asp.net</category><title>Asp.Net MVC, Forms and Missing Values</title><description>&lt;p&gt;Remember, Asp.Net requires that you use the Name and not just ID on your form controls. If you don’t, they don’t come along for the ride to your controller.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-8299217314330605238?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2009/12/aspnet-mvc-forms-and-missing-values.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-5518678480754375686</guid><pubDate>Fri, 04 Dec 2009 16:01:00 +0000</pubDate><atom:updated>2009-12-04T10:01:43.247-06:00</atom:updated><title>RedBox “Verify Your Subscription” Emails</title><description>&lt;p&gt;Anytime I get an unsolicited email saying “verify” something, I’m suspicious. I’ve gotten three of these emails lately. Checking the links, they seem to be genuine. I also found &lt;a href="http://www.hs.facebook.com/redbox?v=feed&amp;amp;story_fbid=185214207009&amp;amp;ref=mf"&gt;this&lt;/a&gt; on Facebook, that seems to indicate they are real. Did notice that lady hadn’t been able to use her code.&lt;/p&gt;  &lt;p&gt;Think I’ll give it a try and see what happens.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-5518678480754375686?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2009/12/redbox-verify-your-subscription-emails.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-9192978345774660278</guid><pubDate>Mon, 23 Nov 2009 00:56:00 +0000</pubDate><atom:updated>2009-11-23T10:51:44.697-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">MVC</category><category domain="http://www.blogger.com/atom/ns#">Cache</category><category domain="http://www.blogger.com/atom/ns#">Compress</category><title>Cache and Compress in Asp.Net MVC</title><description>&lt;p&gt;Found a &lt;a href="http://weblogs.asp.net/rashid/archive/2008/03/28/asp-net-mvc-action-filter-caching-and-compression.aspx" target="_blank"&gt;good entry&lt;/a&gt; on caching at the user browser and compressing the response. Note: It’s from some early beta stuff so be sure to change FilterExecutingConext to ActionExecutingContext. More on that &lt;a href="http://forums.asp.net/t/1249305.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a title="Subscribe to my feed" href="http://feeds.feedburner.com/PaulBrown" type="application/rss+xml" rel="alternate"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" alt="" src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" /&gt;&lt;/a&gt;&lt;a title="Subscribe to my feed" href="http://feeds.feedburner.com/PaulBrown" type="application/rss+xml" rel="alternate"&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-9192978345774660278?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2009/11/cache-and-compress-in-aspnet-mvc.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-6032417121196742670</guid><pubDate>Thu, 19 Nov 2009 03:56:00 +0000</pubDate><atom:updated>2009-11-18T21:56:27.193-06:00</atom:updated><title>Dell Inspiron 1525, Sleep Mode and Magentic Bracelets</title><description>&lt;p&gt;File this in the Hmmm category. Apparently Dell uses a magnet for detecting if the lid has been closed. If you (or your wife) is wearing a magnetic bracelet and it gets close to the sensor, your computer will go to sleep. Leading your wife to yell in frustration. I do need to give her credit, she did figure out it was the bracelet. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-6032417121196742670?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2009/11/dell-inspiron-1525-sleep-mode-and.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-4030384055033944972</guid><pubDate>Fri, 30 Oct 2009 16:22:00 +0000</pubDate><atom:updated>2009-10-30T11:32:03.977-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Navigation</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>Silverlight 3 Page Not Found error</title><description>&lt;p&gt;I was working on a project when all of the sudden I started getting a “Page Not Found” error. Of course the page is there and it had been working fine. Turns out it was the templates infrastructure hiding the error from me.&lt;/p&gt;  &lt;p&gt;When you create a new SL Navigation Application, you’ll find the following in your MainPage.xml.cs.&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;// If an error occurs during navigation, show an error window
private void ContentFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
    e.Handled = true;
    ChildWindow errorWin = new ErrorWindow(e.Uri);
    errorWin.Show();
}&lt;/pre&gt;

&lt;p&gt;This nice little piece of code hides the real cause of the error so that all you see is Page Not Found.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://bryantlikes.com/"&gt;Bryant Likes&lt;/a&gt; has some code that will give you a better idea of the error.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;// If an error occurs during navigation, show an error window
private void ContentFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
    Exception ex = e.Exception;

    while (ex.InnerException != null)
    {
        ex = ex.InnerException;
    }

    e.Handled = true;
    ChildWindow errorWin = new ErrorWindow(ex);
    errorWin.Show();
}&lt;/pre&gt;

&lt;p&gt;This should save a few hours of looking.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-4030384055033944972?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2009/10/silverlight-3-page-not-found-error.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-627020967891594462</guid><pubDate>Fri, 16 Oct 2009 19:18:00 +0000</pubDate><atom:updated>2009-10-16T14:18:01.889-05:00</atom:updated><title>Nice Drop Shadow Border in XAML</title><description>&lt;p&gt;I was working with Silverlight 3 and created this drop shadow border. Enjoy.&lt;/p&gt;  &lt;pre class="brush: xml;"&gt;&amp;lt;Style x:Key=&amp;quot;DropShadow&amp;quot; TargetType=&amp;quot;Border&amp;quot;&amp;gt;
    &amp;lt;Setter Property=&amp;quot;Background&amp;quot; Value=&amp;quot;WhiteSmoke&amp;quot; /&amp;gt;
    &amp;lt;Setter Property=&amp;quot;CornerRadius&amp;quot; Value=&amp;quot;5&amp;quot; /&amp;gt;
    &amp;lt;Setter Property=&amp;quot;BorderThickness&amp;quot; Value=&amp;quot;1,1,4,4&amp;quot; /&amp;gt;
    &amp;lt;Setter Property=&amp;quot;Margin&amp;quot; Value=&amp;quot;10&amp;quot; /&amp;gt;
    &amp;lt;Setter Property=&amp;quot;Padding&amp;quot; Value=&amp;quot;6&amp;quot; /&amp;gt;
    &amp;lt;Setter Property=&amp;quot;BorderBrush&amp;quot;&amp;gt;
        &amp;lt;Setter.Value&amp;gt;
            &amp;lt;LinearGradientBrush&amp;gt;
                &amp;lt;GradientStop Color=&amp;quot;#ccc&amp;quot; Offset=&amp;quot;0&amp;quot; /&amp;gt;
                &amp;lt;GradientStop Color=&amp;quot;#ddd&amp;quot; Offset=&amp;quot;1&amp;quot; /&amp;gt;
            &amp;lt;/LinearGradientBrush&amp;gt;
        &amp;lt;/Setter.Value&amp;gt;
    &amp;lt;/Setter&amp;gt;
&amp;lt;/Style&amp;gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-627020967891594462?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2009/10/nice-drop-shadow-border-in-xaml.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-436877975365667662</guid><pubDate>Thu, 01 Oct 2009 19:51:00 +0000</pubDate><atom:updated>2009-10-11T23:15:49.791-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Primary Key</category><category domain="http://www.blogger.com/atom/ns#">Design Patterns</category><category domain="http://www.blogger.com/atom/ns#">Interfaces</category><category domain="http://www.blogger.com/atom/ns#">LINQ To SQL</category><category domain="http://www.blogger.com/atom/ns#">Repository Pattern</category><category domain="http://www.blogger.com/atom/ns#">Generics</category><title>Using Interfaces, Generics and the Repository Pattern</title><description>&lt;link rel="stylesheet" type="text/css" href="http://alexgorbatchev.com/pub/sh/2.0.320/styles/shCore.css" /&gt;&lt;link id="shTheme" rel="stylesheet" type="text/css" href="http://alexgorbatchev.com/pub/sh/2.0.320/styles/shThemeDefault.css" /&gt;&lt;script language="javascript" src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shCore.js" /&gt;  
	&lt;script language='javascript' src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCSharp.js'/&gt;  
	&lt;script language='javascript'&gt;
		dp.SyntaxHighlighter.bloggerMode = true;
		dp.SyntaxHighlighter.all();  
	&lt;/script&gt;  &lt;p&gt;I’ve been using the repository pattern to insulate my apps from the LINQ to SQL so that I can easily change when (or if) MS kills L2S. The nice thing about this is that I can write a generic repository the encompasses some of the tasks so that the code is consistent for all repositories.&lt;/p&gt;  &lt;p&gt;A little background first. We name all our tables the plural of the objects contained and the first column is an integer primary key named in the singular followed by a “Key” suffix. For example, the Customers table has a first column of CustomerKey. This key name is then used in all related tables as the foreign key column. This makes it very easy to come in behind someone and figure out the data structure.&lt;/p&gt;  &lt;p&gt;This convention gets in the way of making life easier for me because all items have a different name for the primary key. To fix this, created an interface called IPrimaryKey, shown below.&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;public interface IPrimaryKey
{
    int PrimaryKey { get; set; }
}&lt;/pre&gt;

&lt;p&gt;In my database model, I change the name from CustomerKey to PrimaryKey.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_6SIaqZS_bz4/SsUITZosLEI/AAAAAAAAAFE/D-Yoktwlpz0/s1600-h/image%5B11%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_6SIaqZS_bz4/SsUITzyTIPI/AAAAAAAAAFI/dih9SOaUgk8/image_thumb%5B3%5D.png?imgmax=800" width="210" height="186" /&gt;&lt;/a&gt;&amp;#160; &lt;a href="http://lh3.ggpht.com/_6SIaqZS_bz4/SsUIUAoJ-WI/AAAAAAAAAFM/CBxRa04QoXY/s1600-h/image%5B8%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_6SIaqZS_bz4/SsUIUtEqKsI/AAAAAAAAAFQ/h3JUKvfIhRk/image_thumb%5B2%5D.png?imgmax=800" width="205" height="189" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I then create an interface for Customer and a partial class implementing the ICustomer interface. Note that ICustomer adds IPrimaryKey, so any class implementing ICustomer will also have a PrimaryKey.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;public interface ICustomer
     :IPrimaryKey
{
     string FirstName { get; set; }
     string LastName { get; set; }
     string Address { get; set; }
     string City { get; set; }
}

partial class Customer
     : ICustomer
{
}&lt;/pre&gt;

&lt;p&gt;I can now create an interface for my repository and a generic base class that can be inherited by all my other repositories. Creating an interface allows me to use InversionOfConrol to keep my classes flexible, especially for testing.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre class="brush: csharp;"&gt;public interface IRepository&amp;lt;T&amp;gt; where T : IPrimaryKey
{    
    T GetByKey(int key);    

    void Save(T entity);
}

public abstract class RepositoryBase&amp;lt;T&amp;gt;
    : IRepository&amp;lt;T&amp;gt; where T : IPrimaryKey
{    
    protected BogusDbDataContext dc;
    protected IQueryable&amp;lt;T&amp;gt; SourceTable;    

    public T GetByKey(int key)
    {
        return (from x in SourceTable
                where x.PrimaryKey == key                
                select x).SingleOrDefault();    
    }    

    public IQueryable&amp;lt;T&amp;gt; List()    
    {        
        return from x in SourceTable select x;    
    }    

    public abstract void Save(T entity);
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;And finally here is my customers repository.&lt;/p&gt;

&lt;div&gt;
  &lt;pre class="brush: csharp;"&gt;public class CustomersRepository
    : RepositoryBase&amp;lt;ICustomer&amp;gt;, ICustomersRepository
{
    public CustomersRepository()
    {
        dc = new BogusDbDataContext();
        SourceTable = dc.Customers;
    }

    public override void Save(ICustomer entity)
    {
        dc.Customers.InsertOnSubmit((Customer)entity);
    }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Notice that customers has no code to retrieve an entity by it’s primary key. That code exists in RepositoryBase. All my other repositories can use the same code.&lt;/p&gt;

&lt;p&gt;Here is a mock repository and some tests to see how it all fits together.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre class="brush: csharp;"&gt;public class CustomersRepositoryMock
    : RepositoryBase&amp;lt;ICustomer&amp;gt;, ICustomersRepository
{
    private List&amp;lt;ICustomer&amp;gt; customers;

    public CustomersRepositoryMock()
    {
        customers = new List&amp;lt;ICustomer&amp;gt;();

        customers.Add(new Customer() { PrimaryKey = 1, FirstName = &amp;quot;John&amp;quot;, LastName = &amp;quot;Public&amp;quot;, Address = &amp;quot;123 Main&amp;quot;, City = &amp;quot;Somewhereville&amp;quot; });
        customers.Add(new Customer() { PrimaryKey = 2, FirstName = &amp;quot;Larry&amp;quot;, LastName = &amp;quot;Jones&amp;quot;, Address = &amp;quot;456 Oak&amp;quot;, City = &amp;quot;Somewhereville&amp;quot; });
        customers.Add(new Customer() { PrimaryKey = 3, FirstName = &amp;quot;Fred&amp;quot;, LastName = &amp;quot;Smith&amp;quot;, Address = &amp;quot;789 Grand&amp;quot;, City = &amp;quot;Somewhereville&amp;quot; });
        customers.Add(new Customer() { PrimaryKey = 4, FirstName = &amp;quot;Barb&amp;quot;, LastName = &amp;quot;Johnson&amp;quot;, Address = &amp;quot;1234 Cedar&amp;quot;, City = &amp;quot;Somewhereville&amp;quot; });

        this.SourceTable = customers.AsQueryable();
    }

    public override void Save(ICustomer entity)
    {

    }
}
[TestMethod()]
public void GetByKeyTest()
{
    CustomersRepositoryMock repository = new CustomersRepositoryMock();
    int key = 3;
    ICustomer target = repository.GetByKey(key);

    Assert.AreEqual(key, target.PrimaryKey);
}

[TestMethod()]
public void ListTest()
{
    CustomersRepositoryMock repository = new CustomersRepositoryMock();
    IQueryable&amp;lt;ICustomer&amp;gt; target = 
        from x in repository.List()
            where x.LastName.StartsWith(&amp;quot;J&amp;quot;)
            orderby x.LastName
            select x;

    Assert.AreEqual(2, target.Count());
    Assert.AreEqual(&amp;quot;Johnson&amp;quot;, target.First().LastName);
    Assert.AreEqual(&amp;quot;Jones&amp;quot;, target.Last().LastName);
}&lt;/pre&gt;
&lt;/div&gt;
The L2S data context needs to be handled appropriately. I treat the repositories as a unit of work in that I dispose of them almost immediately after use. In this way, I don’t get in trouble with load options. I also try to make sure that I return concrete objects except where I use IQueryable methods. This prevents unwanted problems with a data context that no longer exists. 

&lt;p&gt;There are other interfaces that can be used such as one for Beginning / Ending dates and IsActive. Again, write the code in RepositoryBase and all the derived repositories can use the same code.&lt;/p&gt;

&lt;div class="blogger-post-footer"&gt;&lt;a title="Subscribe to my feed" href="http://feeds.feedburner.com/PaulBrown" type="application/rss+xml" rel="alternate"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" alt="" src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" /&gt;&lt;/a&gt;&lt;a title="Subscribe to my feed" href="http://feeds.feedburner.com/PaulBrown" type="application/rss+xml" rel="alternate"&gt;Subscribe in a reader&lt;/a&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-436877975365667662?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2009/10/using-interfaces-generics-and.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/_6SIaqZS_bz4/SsUITzyTIPI/AAAAAAAAAFI/dih9SOaUgk8/s72-c/image_thumb%5B3%5D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-4991654361657799073</guid><pubDate>Thu, 03 Sep 2009 14:22:00 +0000</pubDate><atom:updated>2009-09-03T09:22:43.801-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">KSOD</category><category domain="http://www.blogger.com/atom/ns#">Vista</category><title>Black Screen Of Death (KSOD) and a possible cause</title><description>&lt;p&gt;I’ve run into my second instance of a KSOD (black screen with mouse pointer and nothing else). Both are laptops and both had similar circumstances. User closed lid and attempted to restart on the next day. Both got Windows started but then encountered problems, shutdown and met the KSOD.&lt;/p&gt;  &lt;p&gt;Theory: I believe what is happening is that the user has the system set to hibernate on the lid closing. This hibernation is occurring when an automated Windows update is in progress. The update then fails because of the hibernation and corrupts the system. Both systems get to CRCDISK.SYS and then die.&lt;/p&gt;  &lt;p&gt;The only solution I’ve found is to reimage or reinstall. I tried all of the registry changes, sticky keys and booting from another source. No luck.&lt;/p&gt;  &lt;p&gt;Solution: Upgrade to Win7, turn hibernate off and teach users to shutdown.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-4991654361657799073?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2009/09/black-screen-of-death-ksod-and-possible.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-1614539500321194380</guid><pubDate>Fri, 31 Jul 2009 15:01:00 +0000</pubDate><atom:updated>2009-07-31T10:01:05.534-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Checkbox</category><category domain="http://www.blogger.com/atom/ns#">jquery</category><title>Jquery for Select All Checkbox</title><description>&lt;p&gt;A very common interface is a list of items with a checkbox to select each and them you perform an action on those selected. Typically you have a checkbox at the top to toggle all of the list. This script will take care of everything for you. You can exclude elements by checking the ID or name properties.&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre id="codeSnippet" class="csharpcode"&gt;$(document).ready(&lt;span class="kwrd"&gt;function&lt;/span&gt;() {&lt;br /&gt;    $(&lt;span class="str"&gt;&amp;quot;#selectAllCheckBox&amp;quot;&lt;/span&gt;).click(&lt;span class="kwrd"&gt;function&lt;/span&gt;() {&lt;br /&gt;            &lt;span class="kwrd"&gt;var&lt;/span&gt; checked_status = &lt;span class="kwrd"&gt;this&lt;/span&gt;.&lt;span class="kwrd"&gt;checked&lt;/span&gt;;&lt;br /&gt;            $(&lt;span class="str"&gt;&amp;quot;input[type=CheckBox]&amp;quot;&lt;/span&gt;).each(&lt;span class="kwrd"&gt;function&lt;/span&gt;() {&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.id != &lt;span class="str"&gt;&amp;quot;pleaseSkipMe&amp;quot;&lt;/span&gt;) {&lt;br /&gt;                    &lt;span class="kwrd"&gt;this&lt;/span&gt;.&lt;span class="kwrd"&gt;checked&lt;/span&gt; = checked_status;&lt;br /&gt;                }&lt;br /&gt;            });&lt;br /&gt;        });&lt;br /&gt;    });&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-1614539500321194380?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2009/07/jquery-for-select-all-checkbox.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1934426700208076473.post-3781810426536584436</guid><pubDate>Fri, 24 Jul 2009 20:22:00 +0000</pubDate><atom:updated>2009-07-24T15:22:15.389-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Ajax</category><title>Ajax Call Issue</title><description>&lt;p&gt;When making an Ajax call, remember to make sure that your target element can accept the result of your call. For example, if I return a string from my call to a target element of &amp;lt;p&amp;gt;, everything is fine. Replace that with a table and you’ll get the lovely message “htmlfile: Unknown runtime error”. Change to a &amp;lt;div&amp;gt; and everything is fine.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0"/&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/PaulBrown" title="Subscribe to my feed" rel="alternate" type="application/rss+xml"&gt;Subscribe in a reader&lt;/a&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1934426700208076473-3781810426536584436?l=pretzelsteelersfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pretzelsteelersfan.blogspot.com/2009/07/ajax-call-issue.html</link><author>noreply@blogger.com (PretzelSteelersFan)</author><thr:total>0</thr:total></item></channel></rss>

