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

Aar*_*her 3 ormlite-servicestack

我有一张桌子

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 
Run Code Online (Sandbox Code Playgroud)

我的课

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; }
    }
Run Code Online (Sandbox Code Playgroud)

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

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

ANe*_*ves 5

您可以使用标注ID [ServiceStack.DataAnnotations.AutoIncrement].

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