Posts

Updated Code To Get Class Definition From Table Structure

My previous post on Script to Create MetadataType classes 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. Enjoy. 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 (SqlDat...

Replacement for ExpectedException in MS Test

This StackOverflow thread 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.

Script To Grab Column Names As UML Properties

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. Enjoy! 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', 'd...

SQL To Find String In Procedure/Function

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. 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%' INFORMATION_SCHEMA.ROUTINES is unreliable because it is limited to the first 4000 characters. Enjoy!!

Read XML File Into SQL Server

Wayne Sheffield has a nice article on reading XML files into sql. You can find it here.

User Story Screen

Image
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. Here’s the User Story screen from VS.   Title – A one sentence description of the story. Assigned To – The single individual responsible for the story. State – Indicates the current state of the story. Active – The story is currently being worked on or waiting to be worked on. Closed – The story was closed without being resolved. Resolved – The story was completed and implemented. Reason – The reason the item is in the current state. Matching states are in parenthesis. New – A new story (Active). Abandoned – The st...

A Simple Man’s Guide To Using VS & TFS 2010

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. 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. 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. The first step will be to create a user story for each discrete activity. Then we’ll write the test cases that insure things ...