3

我有一张桌子

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 忽略自动增量字段,以便我可以插入项目?

4

2 回答 2

5

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

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

于 2013-11-13T16:21:24.303 回答
0

对于遇到此问题的任何其他人,该[ServiceStack.DataAnnotations.Compute]属性告诉 OrmLite 忽略插入/更新的列。

于 2018-01-31T22:41:46.223 回答