TinyInt to SmallInt primary keys change

Jan 19, 2013 at 10:57 AM

Hello everybody,

I am new to nHydrate and yesterday I noticed something on which I would like to ask your advice.

I had a few entities with a tinyint Id field as primary key, which i thought had been also an identity (autoincrement by the database). These Id's were refernced in other tables as foreign keys through associations I had implemented in the model. Yesterday I discovered that tinyint cannot become identities in nHydrate (I was surprised, but I found out it is indeed documented). I had to change all my tinyint PK's to smallint, and then do the same for the associated FK's. When I tried to run the Install project to update my database, I got the errors that the PK's are used and cannot be dropped. I went back to the model, and deleted and recreated all the associations. However the installation kept giving those errors. I ended up creating a new database from scratch.

My question is: Is there a recommended procedure for this kind of changes? I would expect to have a problem from the SQL Server side if I tried to change a smallint to tinyint (possible loss of data) but not when increasing the size of a field. How are these cahnges treated by the nHydrate database updating engine?

Thanks,

Alex 

Coordinator
Jan 20, 2013 at 2:24 AM
Edited Jan 20, 2013 at 2:24 AM

In the next version of the product there will be a refactor rule added that will change a primary key's data type. This will walk all relations and change the necessary fields as well. An upgrade script will be automatically generated to apply these changes to your database. For now this will only work for single column primary keys. Your life just got a little bit easier.

Jan 20, 2013 at 8:21 AM

That will be really great! 

Two minor questions:

1. Since I am new, when you say next version you mean next public release, nightly build, major version, minor version change or what? More generally, how do we know when we need to change version?

2. What does version changing involve? What do we need to un-install/re-install? 

Many thanks,

Alex

Coordinator
Jan 20, 2013 at 1:47 PM

The version that was released this morning Sunday Jan, 20. It is available for download. You can always read the release notes to see what changed. 

http://nhydrate.codeplex.com/wikipage?title=Release%20Notes

After you download the new version, uninstall your current version. Then re-install the new version. This consists of just the MSI file you downloaded. Make sure VS.NET is closed when you do this.

Jan 20, 2013 at 8:03 PM

Thanks for your answer.

I downloaded and installed the nhydrate.msi after having uninstalled the previous version.

However, I seem to have installed one more thing which shows up as Name:nHydtate, Publisher:Widgetsphere, Size:4.20MB, Version:1.0.0" in my Programs and Features. I'm pretty sure it comes from the "nHydrate VS 2010 Install" from the "Other Available Downloads" of the "Downloads" section, which I must have installed when I first installed the software.

The question is, what is this and do I need it?

Thanks,

Alex

Coordinator
Jan 21, 2013 at 1:24 AM

You only need the "nHydrate Modeler" in your installed programs. That may be some example project. Please check your installed apps to see if there is something else under the N's or W's