This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Can a unique constrant be added to a column by setting the Validate Unique property to true. We use migrations to create the database and it is not adding the constrant to the database field. We are using SqlServer2005 db provider.
|
|
|
Thanks for drawing our attention to this. We have now added support for this and it will be included in the 28 April 2010 nightly, available from about 1500 GMT. |
|
|
Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4 Thanks for adding this feature but it doesnt work for a couple cases. Can these be fixed as well?
First, if I have changed the databaseNativeType to specify the field size. Which I have to do because you can not set a unique constrant on a VARCHAR(MAX). Below is my enityProperty xml definition and the code it generates which doesn't compile because of the "VARCHAR(3)" param.
<entityProperty name="ISOAlphabeticCode" databaseNativeType="VARCHAR(3)"> <validations> <uniquenessValidation /> </validations> </entityProperty>
this.AddColumn("CurrencyExchangeRates", null, "ISOAlphabeticCode", "VARCHAR(3)", false, null, true);
Also when creating a table from scratch the code that is generated does not include the unique attribute. Here is the code that is generated in that case:
public override void Up() { this.AddTable("CurrencyExchangeRates", null, new Field("Id", ModelDataType.Int64, false), new Field[] { new Field("ISOAlphabeticCode", "VARCHAR(3)", false), new Field("Rate", ModelDataType.Decimal, false), new Field("CreatedOn", ModelDataType.DateTime, false), new Field("UpdatedOn", ModelDataType.DateTime, false), new Field("LockVersion", ModelDataType.Int32, false)}); }
Even if I modify the code above to set the unique property to true like this: new Field("ISOAlphabeticCode", "VARCHAR(3)", false){Unique = true},
the unique contrant is not added to the db table.
|
|
|
Thanks for alerting us to these issues -- we'll try to get them fixed. However, to specify the size for a field, you don't need to use a native database type -- just provide the size parameter: this.AddColumn("CurrencyExchangeRates", null, "ISOAlphabeticCode", If you're generating the migrations from the designer, then setting Validate Length to "<= 3" (or adding a Length Validation) will generate this automatically for you. However this won't help with the AddTable scenario -- only when doing an AddColumn. As an interim measure, I've committed a fix so that adding { Unique = true; } to the field declaration (as in your last code snippet) should now work (beginning with the 8 May nightly build), but it may take a bit longer to get the designer to generate it automatically. Thanks again for reporting these issues. |
|