What's hot ? (and I mean really ...) - scroll down for more
1).  Code Templating - advanced usage of delegates & generics: my slides & demos are available for download! CodeProject article is also available.

2).  My series "TDD in the eyes of a simpleminded" is in progress(including code!): preface, part1, part2, Q&A 1, Manual Stub .vs. Mock Stub

3).  TDD Workshop: SeeCompass v0.1 and v0.2 are out.
# Sunday, February 05, 2006

I just found a bug in the new version of SchemaExplorer (3.2.4.797) at MemberColumnSchemaCollection.Contains(CoolumnSchema value) method.
Posted by Oren Ellenbogen 
05/02/2006 02:25, Israel time UTC+02:00,     Comments [1]  | 
# Wednesday, February 01, 2006

I've just upgraded my CodeSmith version to 3.2; It went pretty well just until I've opened the CodeSmith Studio and tried to compile my template. I got a strange NullReferenceException in the CodeSmith.Engine.CodeTemplate constructor.
I thought about 2 reasons which can cause this behavior:

  1. Maybe the CodeSmith Studio works with an old version of one of the dlls, for some unknown reason (unlikely).
  2. I'm using a compiled dll as my CodeTemplate base class, maybe I need to recompile it again and then try to compile the template (more likely).

So I compiled my DLL (and did a quick restart to my computer, just to be safe) - now it works...

Posted by Oren Ellenbogen 
01/02/2006 10:25, Israel time UTC+02:00,     Comments [0]  | 
# Sunday, January 22, 2006

This post is mostly a self reminder but it may come useful if you're using CodeSmith as well.
It is possible to check if a (schema)column is an identity field via ExtendedProperties property of the SchemaObjectBase class:

// Only for Sql Server
private bool IsIdentityColumn(ColumnSchema column)
{
   return (bool)column.ExtendedProperties["CS_IsIdentity"].Value;
}

There is one exception though and that's if you're sending the column object through the TableSchema.ForeignKey[index].ForeignKeyMemberColumns or TableSchema.ForeignKeys[index].PrimaryKeyMemberColumns, meaning:

for(int i=0; i<MySourceTable.ForeignKeys.Count; i++)
{
   // Same thing about MySourceTable.ForeignKeys[i].PrimaryKeyMemberColumns...
   for (int j=0; j<MySourceTable.ForeignKeys[i].ForeignKeyMemberColumns.Count; j++)
   {
      if (IsIdentityColumn(MySourceTable.ForeignKeys[i].ForeignKeyMemberColumns[j])) // <-- Exception Here.
      {
         //do some code
         
      }
   }   
}

The extended properties will NOT hold the key "CS_IsIdentity" and IsIdentityColumn will throw an exception (null reference). I'm still not sure if this is by design or not, so I'll try to fish it out on from the net and update the post later on. 

The solution is simply working a little harder via TableSchema.Keys and than verify the type of the key (by PrimaryKeyTable and ForeignKeyTable properties).

update:
This is quite a dirty hack, but it works and I'm loving it (I don't have to change a lot of code in a lot of different places) !  
I refactor the mehotd IsIdentityColumn so it will do the trick:

private bool IsIdentityColumn(ColumnSchema column)
{
   if (column.ExtendedProperties["CS_IsIdentity"] == null)
      column = column.Table.Columns[column.Name];

   return (bool)column.ExtendedProperties["CS_IsIdentity"].Value;
}

Back to code...

Posted by Oren Ellenbogen 
22/01/2006 10:31, Israel time UTC+02:00,     Comments [0]  | 
# Friday, January 13, 2006

I like to handle my .cst(CodeSmith templates files) files with my VS.NET for it's integration with Visual Source Safe.
Well, no need for VSTweaks in this version of Visual Studio, The trick is quite simple:

  1. Open you Visual Studio .Net 2005.
  2. Tools -> Options -> Text Editor -> File Extension
  3. In the "Extension" text-box write ".cst" and in the "Editor" drop-down-list select "Html Editor".
This will put some color to your .cst files.
Sweet.
Posted by Oren Ellenbogen 
13/01/2006 12:27, Israel time UTC+02:00,     Comments [0]  | 
# Tuesday, November 22, 2005

Well, Richard explains it better than me, so just read his post.

update: for some reason the link doesn't work well, so here is the full address:

http://blog.hundhausen.com/Database+Concordance+Generator+CodeSmith+Style.aspx

Just copy it and put it in the address bar, sorry for the inconvenience.

Posted by Oren Ellenbogen 
22/11/2005 05:00, Israel time UTC+02:00,     Comments [0]  |