gpt4 book ai didi

ormlite-servicestack - 您如何配置 ormlit 以支持不是主键的自动增量列?

转载 作者:行者123 更新时间:2023-12-01 11:42:34 26 4
gpt4 key购买 nike

我有一张 table

CREATE TABLE [dbo].[ServiceTestCase](
[SSN] [int] IDENTITY(600000001,1) NOT NULL,
[Description] [varchar](max) NULL,
[EmbeddedResponse] [varchar](max) NULL,
[ResponseType] [varchar](50) NULL,
[DocumentType] [varchar](50) NULL,
[Id] [uniqueidentifier] NOT NULL,
[ServiceType] [varchar](50) NOT NULL,
CONSTRAINT [PK_TestCase] PRIMARY KEY CLUSTERED

我的课
public class ServiceTestCase
{
public ServiceTestCase ()
{

}
public string ServiceType { get; set; }
[ServiceStack.DataAnnotations.AutoIncrement]
public Guid Id { get; set; }
[ServiceStack.DataAnnotations.AutoIncrement]
public long SSN { get; set; }
public string Description { get; set; }
public string EmbeddedResponse { get; set; }
public EmbeddedResponseType ResponseType { get; set; }
public EmbeddedDocumentType DocumentType { get; set; }
}

当我调用 db.Insert ( new ServiceTestCase {/* Id = testId, */ServiceType = "Credit"} );
我收到以下错误:
System.Data.SqlClient.SqlException:当 IDENTITY_INSERT 设置为 OFF 时,无法为表“ServiceTestCase”中的标识列插入显式值。

如何让 ormlite 忽略自动增量字段,以便我可以插入一个项目?

最佳答案

您可以使用 [ServiceStack.DataAnnotations.AutoIncrement] 注释 Id .

来源:https://groups.google.com/forum/#!msg/servicestack/JM09UGMZpkY/Klnmwq5pWoMJ

关于ormlite-servicestack - 您如何配置 ormlit 以支持不是主键的自动增量列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18088824/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com