Debasish
09/11/2023, 5:33 AMCREATE TABLE [dbo].DistCache
(
[Id] NVARCHAR(900) NOT NULL PRIMARY KEY,
[Value] VARBINARY(MAX) NOT NULL,
[ExpiresAtTime] DATETIMEOFFSET NOT NULL,
[SlidingExpirationInSeconds] BIGINT NULL,
[AbsoluteExpiration] DATETIMEOFFSET NULL
)
I wanted to do this programmatically on application start. I tried to follow this article here https://docs.umbraco.com/umbraco-cms/v/10.latest-lts/extending/database. Here is my Disc Cache Schema
[TableName("dbo.DistCache")]
[PrimaryKey("Id")]
[ExplicitColumns]
public class DistCacheSchema
{
[PrimaryKeyColumn()]
[Column("Id")]
public String Id { get; set; }
[Column("Value")]
public Byte[] Value { get; set; }
[Column("ExpiresAtTime")]
public DateTimeOffset ExpiresAtTime { get; set; }
[Column("SlidingExpirationInSeconds")]
public Nullable<Int64> SlidingExpirationInSeconds { get; set; }
[Column("AbsoluteExpiration")]
public Nullable<DateTimeOffset> AbsoluteExpiration { get; set; }
}
This fails with the following error message
Microsoft.Data.SqlClient.SqlException: 'Identity column 'Id' must be of data type int, bigint, smallint, tinyint, or decimal or numeric with a scale of 0, unencrypted, and constrained to be nonnullable.'
Any ideas how to get this work?Sean Thorne
09/11/2023, 8:21 AMNVARCHAR
is not a valid type for the identity column. You can change it to int?
ALTER TABLE [dbo].DistCache
ALTER COLUMN [Id] INT IDENTITY(1,1);
Sean Thorne
09/11/2023, 8:22 AMDebasish
09/11/2023, 10:00 AMSean Thorne
09/11/2023, 10:59 AM[PrimaryKeyColumn(AutoIncrement = true, IdentitySeed = 1)]
[Column("PrimaryKey")]
public int PrimaryKey { get; set; }
Matt Wise
09/11/2023, 11:15 AMMatt Wise
09/11/2023, 11:16 AM