Sql server PK以外字段上的ServiceStack标识-插入失败
当我尝试使用下面类中的对象在ServiceStack(针对SQL Server 2014)中使用“插入”函数时,它尝试为ContactId插入0(ContactId属性的默认值),而不是在数据库中自动生成一个。ContactId是Sql server PK以外字段上的ServiceStack标识-插入失败,sql-server,
servicestack,sql-server-identity,Sql Server,
servicestack,Sql Server Identity,当我尝试使用下面类中的对象在ServiceStack(针对SQL Server 2014)中使用“插入”函数时,它尝试为ContactId插入0(ContactId属性的默认值),而不是在数据库中自动生成一个。ContactId是标识非空的。ContactId是聚集索引,而GlobalContactId是非聚集主键 [Alias("Contact")] [Schema("Customer")] public partial class Contact { [PrimaryKey]
标识非空的
。ContactId是聚集索引,而GlobalContactId是非聚集主键
[Alias("Contact")]
[Schema("Customer")]
public partial class Contact
{
[PrimaryKey]
public Guid GlobalContactId { get; set; }
[AutoIncrement]
public int ContactId { get; set;}
...
我这样做是因为:
[AutoIncrement]
,并且该值与该类型的默认值匹配,那么它将假定该值未设置
编辑
现在我只是恢复使用ContactId作为PK和identity,并在OrmLite中添加带有唯一检查约束的uniqueidentifier,
[AutoIncrement]
属性用于指定自动递增主键。因此,它不能用于非主键列。可能的重复项不是重复项。这个问题是关于具有自动增量的表的PK的,我知道如何处理它。在这种情况下,标识字段不是主键。这可能会有所帮助@AlexKudryashev我使用的属性是特定于ServiceStack的