Unique Constraint not being picked up

Posts   
 
    
he00273
User
Posts: 133
Joined: 02-Oct-2008
# Posted on: 10-Nov-2009 04:07:08   

I have created a new table in my SQL Server 2008 database. I want to get an entity based on a unique constraint

I have followed this http://msdn.microsoft.com/en-us/library/ms190024.aspx

To create a unique constraint

  1. In Object Explorer, right-click the table to which you want to add a unique constraint, and click Design. The table opens in Table Designer. 2.From the Table Designer menu, click Indexes/Keys. 3.In the Indexes/Keys dialog box, click Add.
  2. In the grid, click Type and choose Unique Key from the drop-down list box to the right of the property.

I have looked in the Indexes folder and have this index UNIQUE NONCLUSTERED INDEX [IDX_SystemFileKey] ON [Global].[SystemFile]

All looks sweet. sunglasses

I refresh the catalogue for my LLBLGen Pro project, added in my new table and ran generate.

Where can one see in the output of the generator that support for the unique constraint exists?confused

I rebuilt the two llblgen pro projects and then tried to use the unqiue constraint

        public MainDictionary(string connectionString)
        {
            connection_String = connectionString;

            using (var adaptor = new DataAccessAdapter(connectionString))
            {
                try
                {
                    connection_String = connectionString;
                    SystemFileEntity MainDictionary = new SystemFileEntity();
                    MainDictionary.SystemFileKey = MainDictionaryKey; 
                    adaptor.FetchEntityUsingUniqueConstraint(MainDictionary, MainDictionary.ConstructFilterForUCSystemFileKey());
                }
                catch (Exception e)
                {
                    throw new Exception("Cannot acquire main system dictionary",e);
                }
            }
        }

There is no ConstructFilterForUCSystemFileKey() for the MainDictionary entityrage

he00273
User
Posts: 133
Joined: 02-Oct-2008
# Posted on: 10-Nov-2009 04:26:34   

Ok just found http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=6333&HighLight=1 on the forums

Looks like I need do some more investigative work. I need to create a unique constraint not just a unique non clustered index (Do I need both? !!!)

It appears Microsoft's concept of a unique constraint is not 100% aligned with yours.

Such is life frowning

I will probably have to use T-SQL to do this. disappointed

he00273
User
Posts: 133
Joined: 02-Oct-2008
# Posted on: 10-Nov-2009 04:55:11   

ALTER TABLE Global.SystemFile ADD CONSTRAINT UC_SystemFileKey UNIQUE(SystemFileKey)

Apart from the name it looks the same in ssms.

I was gonna have another winge when it did not work but then stupid remembered he had not refreshed the schema.

Its all sweet now. smile

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Nov-2009 06:49:28   

Yes, it must be unique constraint, instead of just unique index. Good you have it working now wink

David Elizondo | LLBLGen Support Team