Reputation: 9983
When I try to use the "Insert" function in ServiceStack (against SQL Server 2014) using an object from the below class, it tries to insert a 0 (default of the ContactId property) for the ContactId instead of auto generating one in the database. ContactId is IDENTITY NOT NULL
. ContactId is the clustered index, but GlobalContactId is the nonclusted primary key.
[Alias("Contact")]
[Schema("Customer")]
public partial class Contact
{
[PrimaryKey]
public Guid GlobalContactId { get; set; }
[AutoIncrement]
public int ContactId { get; set;}
...
I'm doing this because:
I would have thought that if a property has [AutoIncrement]
and the value matches the default for that type then it would assume the value was not set.
Edit
For now I'm just reverting to using ContactId as both PK and identity, and adding the uniqueidentifier with a unique check constraint
Upvotes: 1
Views: 105
Reputation: 143319
In OrmLite the [AutoIncrement]
attribute is for specifying an Auto Incrementing primary key. So it can't be be used on a non-Primary Key column.
Upvotes: 2