2013-08-06 27 views
3

我有一個表如何配置ormlit以支持不是主鍵的自動增量列?

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(新ServiceTestCase {/ *身份證= testId,* /服務類型= 「信用」}); 我收到以下錯誤: System.Data.SqlClient.SqlException:當IDENTITY_INSERT設置爲OFF時,無法在表'ServiceTestCase'中爲標識列插入顯式值。

我該如何讓ormlite忽​​略autoincrement字段,以便我可以插入一個項目?

回答

0

對於其他人誰絆倒了這一點,[ServiceStack.DataAnnotations.Compute]屬性告訴OrmLite忽略的插入/更新的列。