Tuesday, August 19, 2008

Alternative Unique Key Fix

Code OnTime Generator is using a collection of queries to interrogate a database schema when any code generator project involving database interaction is generated. File [My Documents]\Code OnTime\Library\_Config \CodeOnTime.ModelMap.xml defines a collection of queries that are used to discover the database metadata. Data provider System.Data.SqlClient  has an entry named PrimaryKeyColumns that was incorrectly determining the primary key columns. The query has been retrieving both primary keys and alternative unique keys. Alternative unique keys should be ignored.

Generated projects were treating fields included in the alternative unique keys as if they were the fields of the primary key.

We have replaced the query with the following:

select kcu.*
from information_schema.key_column_usage kcu 
    inner join information_schema.table_constraints tc on
        kcu.constraint_catalog = tc.constraint_catalog and
        kcu.constraint_schema = tc.constraint_schema and
        kcu.constraint_name = tc.constraint_name 
where 
    tc.constraint_type = 'PRIMARY KEY'

The fix has been deployed. Simply start CodeOnTime.exe and you will be prompted to download the update.

If you do have a database table with any fields included in a UNIQUE INDEX then open you project and proceed to the Database Connection section of your project. There is a link "Click here if your database has changed and you would like to refresh the cached metadata." Click on the link to reset the metadata and generate the project again. The problem will go away.

No comments:

You can find more about Code OnTime Generator, Data Aquarium Framework, and other great products here.


© 2010 Code OnTime LLC. Intelligent code generation software for ASP.NET. Visit us at http://codeontime.com