Error creating Entity using a Unique column restriction

Topics: Customizing Orchard, Writing modules
Apr 29, 2014 at 11:03 AM
Hey guys, can anyone shed some light into this issue that I'm having?

When I create a table for my record using "column => column.NotNull().Unique()" I get an exception saving a new entity, but if I remove the restrictions from the column it works fine...

Exception details:
first Exception:

An exception of type 'NHibernate.Exceptions.GenericADOException' occurred in NHibernate.dll but was not handled in user code
Additional information: could not insert: [InternalName.Core.Records.TenantRecord#15][SQL: INSERT INTO InternalName_Core_TenantRecord (GroupCode, Description, CurrentDeployment, Id) VALUES (?, ?, ?, ?)]

Inner Exception:
The column cannot contain null values. [ Column name = GroupCode,Table name = InternalName_Core_TenantRecord ]


second Exception:

An exception of type 'NHibernate.AssertionFailure' occurred in NHibernate.dll but was not handled in user code

Additional information: null id in Orchard.ContentManagement.Records.ContentTypeRecord entry (don't flush the Session after an exception occurs)

Code that throws the exception:
        // Creating table Tenant
        SchemaBuilder.CreateTable("TenantRecord", table => table
            .ContentPartRecord()
            .Column("GroupCode", DbType.String, column => column.NotNull().Unique())
            .Column("Description", DbType.String)
            .Column("CurrentDeployment", DbType.String)
Code that Works:
        // Creating table Tenant
        SchemaBuilder.CreateTable("TenantRecord", table => table
            .ContentPartRecord()
            .Column("GroupCode", DbType.String)
            .Column("Description", DbType.String)
            .Column("CurrentDeployment", DbType.String)