CodeSmith 3.2 version break

I just found a bug in the new version of SchemaExplorer (3.2.4.797) at MemberColumnSchemaCollection.Contains(CoolumnSchema value) method.

How to reproduce:


DB:

awbtables.JPG

Code:


SqlSchemaProvider p = new SqlSchemaProvider();
DatabaseSchema db = new DatabaseSchema(p, “your-connection-string”);
TableSchema table = db.Tables[“E_AWBs”];

// Returns true
bool isFound = Test(table.Columns[“FlightNO”]);

// Returns false – in the previous version it worked just fine
bool isFoundTPK = Test(table.PrimaryKey.MemberColumns[“FlightNO”]);

public static bool Test(ColumnSchema column)
{
   TableSchema tbl = column.Table;
   foreach (TableKeySchema key in tbl.ForeignKeys)
   {
      if (key.ForeignKeyMemberColumns.Contains(column))
         return true;
   }

   return false;
}



My opinion:

I’m not sure how the code is written (the reflector shows me the message “This item appears to be obfuscated and can not be translated“) but my guess is that table.PrimaryKey.Columns return a shallow copy of table.Columns and therefore the Contains method don’t work properly.



Workaround:



  1. The quick solution is quite dirty but is simple and match the same solution I did before

    column = column.Table.Columns[column.Name]; // Change the pointer to address the real column


  2.  The other solution is to foreach the key.ForeignKeyMemberColumns and match column name and table name as needed.


I’ll open a bug(I’m not sure it’s the right definition) at CodeSmith support forum.


update [06.02.2006]:
Just got an answer from Eric J. Smith “This issue should be resolved for the next maintenance release.”

 

Oren Ellenbogen