Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server PK以外字段上的ServiceStack标识-插入失败_Sql Server_<img Src="//i.stack.imgur.com/WM7S8.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">servicestack_Sql Server Identity - Fatal编程技术网 servicestack,sql-server-identity,Sql Server,servicestack,Sql Server Identity" /> servicestack,sql-server-identity,Sql Server,servicestack,Sql Server Identity" />

Sql server PK以外字段上的ServiceStack标识-插入失败

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]

当我尝试使用下面类中的对象在ServiceStack(针对SQL Server 2014)中使用“插入”函数时,它尝试为ContactId插入0(ContactId属性的默认值),而不是在数据库中自动生成一个。ContactId是
标识非空的
。ContactId是聚集索引,而GlobalContactId是非聚集主键

[Alias("Contact")]
[Schema("Customer")]
public partial class Contact
{
    [PrimaryKey]
    public Guid GlobalContactId { get; set; }
    [AutoIncrement]
    public int ContactId { get; set;}
     ...
我这样做是因为:

  • 它是一个分布式应用程序,需要给家里打电话——因此是guid
  • 这是一种旧数据的导入,用户更容易引用int而不是guid(至少对于他们的特定位置而言),并且他们希望继续前进
  • 由于性能原因,我将ContactId用作其他表的FK,这些表的数据不能打电话回家
  • 我原以为,如果属性具有
    [AutoIncrement]
    ,并且该值与该类型的默认值匹配,那么它将假定该值未设置

    编辑


    现在我只是恢复使用ContactId作为PK和identity,并在OrmLite中添加带有唯一检查约束的uniqueidentifier,
    [AutoIncrement]
    属性用于指定自动递增主键。因此,它不能用于非主键列。

    可能的重复项不是重复项。这个问题是关于具有自动增量的表的PK的,我知道如何处理它。在这种情况下,标识字段不是主键。这可能会有所帮助@AlexKudryashev我使用的属性是特定于ServiceStack的