我有一张桌子
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 =“/*”})时,我得到以下错误: System.Data.SqlClient.SqlException :当IDENTITY_INSERT设置为OFF时,无法为表'ServiceTestCase‘中的标识列插入显式值。
我怎样才能让ormlite忽略自动增量字段,这样我才能插入项目?
发布于 2013-11-14 00:21:24
您可以使用[ServiceStack.DataAnnotations.AutoIncrement]对Id进行注释。
来源:https://groups.google.com/forum/#!msg/servicestack/JM09UGMZpkY/Klnmwq5pWoMJ
发布于 2018-02-01 06:41:46
对于遇到这个问题的其他人,[ServiceStack.DataAnnotations.Compute]属性告诉OrmLite忽略插入/更新的列。
https://stackoverflow.com/questions/18088824
复制相似问题