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
700 stars 230 forks source link

Error: Cannot insert an explicit value into a timestamp column #753

Closed nealculiner closed 2 years ago

nealculiner commented 2 years ago

I'm trying to add a new entity in EF Core 5 and I'm getting an error due to a column that has a time stamp data type (nullable). The error returned is:

Cannot insert an explicit value into a timestamp column

I think what's missing in the generator for a timestamp column per a google search on this error is it possibly needs:

.ValueGeneratedOnAddOrUpdate();

Before:

builder.Property(x => x.ts).HasColumnName(@"ts").HasColumnType("timestamp").IsRequired(false);

After:

builder.Property(x => x.ts).HasColumnName(@"ts").HasColumnType("timestamp").IsRequired(false).ValueGeneratedOnAddOrUpdate();

https://entityframeworkcore.com/knowledge-base/45825877/inserting-record-in-sql-table-with-timestamp-datatype

nealculiner commented 2 years ago

Adding the .ValueGeneratedOnAddOrUpdate(); resolved my issue. I'd offer this is a critical/blocker issue

sjh37 commented 2 years ago

Thanks Neal, I'll get this added.

nealculiner commented 2 years ago

Any timeline when we'll get an update for this? I really need this fixed ASAP please. I believe this affects RowVersion column types too.

nealculiner commented 2 years ago

I think the generator is missing the .IsRowVersion() method on this column type when it's set to required.

sjh37 commented 2 years ago

Hi @nealculiner Looking into now.

sjh37 commented 2 years ago

Created wiki article https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/wiki/RowVersion-and-TimeStamp-columns

sjh37 commented 2 years ago

Got it sorted @nealculiner. Thanks for your patience.

Grab the latest code from EF.Reverse.POCO.v3.ttinclude and replace your project file with it.

Any problems, give me a shout.

nealculiner commented 2 years ago

Thank you

nealculiner commented 2 years ago

@sjh37 did you commit your changes as I don't see anything different yet?

sjh37 commented 2 years ago

Sorry my bad, It's on the development branch. Here it is development/EF.Reverse.POCO.v3.ttinclude

sjh37 commented 2 years ago

Now released in 3.6.1