sjh37 / EntityFramework-Reverse-POCO-Code-First-Generator

EntityFramework Reverse POCO Code First Generator - Beautifully generated code that is fully customisable. This generator creates code as if you reverse engineered a database and lovingly created the code by hand. It is free to academics (you need a .edu or a .ac email address), not free for commercial use. Obtain your licence from
https://www.reversepoco.co.uk/
Other
710 stars 227 forks source link

Timestamp Column generated with length which is invalid #706

Open kcadduk opened 3 years ago

kcadduk commented 3 years ago

I have a table with a Version column, defined as a timestamp column. (I know its deprecated, but this is older framework)

CREATE TABLE [dbo].[Table]
(
  [RecordTimeStamp] [datetime] NOT NULL
  [Version] [timestamp] NOT NULL,
  [ID] [int] IDENTITY(1,1) NOT NULL,
  CONSTRAINT [PK_aAccount] PRIMARY KEY CLUSTERED ( [ID] ASC )
) 

When it generates the configuration, it is generating the following

builder.Property(x => x.Version)
    .HasColumnName(@"Version")
    .HasColumnType("timestamp(8)")
    .IsRequired()
    .IsFixedLength()
    .HasMaxLength(8)
    .IsRowVersion();

which fails on EF migrate because it throws an exception

Microsoft.Data.SqlClient.SqlException (0x80131904): Column, parameter, or variable #10:
Cannot specify a column width on data type timestamp;
kcadduk commented 3 years ago

At the minute, i've put this into the Settings.UpdateColumn

if (column.NameHumanCase.Equals("Version", StringComparison.InvariantCultureIgnoreCase))
{
   column.IsRowVersion = true;
   column.MaxLength = 0;
   column.SqlPropertyType = "rowversion";
}

But I feel that this is a workaround of a bug perhaps?