Skip to content

Commit 2544fa7

Browse files
committed
#753 Fix for ROWVERSION and TIMESTAMP columns. Thanks to Neal Culiner.
1 parent 2d0ffd8 commit 2544fa7

File tree

8 files changed

+33
-4
lines changed

8 files changed

+33
-4
lines changed

BuildTT/BuildTT.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ private static void CreateTT(string generatorRoot, string ttRoot)
365365
column.Attributes.Add(""[MaxLength]"");
366366
367367
if (column.IsRowVersion)
368-
column.Attributes.Add(""[Timestamp]"");
368+
column.Attributes.Add(""[Timestamp, ConcurrencyCheck]"");
369369
370370
if (!column.IsMaxLength && column.MaxLength > 0)
371371
{

EntityFramework.Reverse.POCO.Generator/Database.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@
349349
column.Attributes.Add("[MaxLength]");
350350

351351
if (column.IsRowVersion)
352-
column.Attributes.Add("[Timestamp]");
352+
column.Attributes.Add("[Timestamp, ConcurrencyCheck]");
353353

354354
if (!column.IsMaxLength && column.MaxLength > 0)
355355
{

EntityFramework.Reverse.POCO.Generator/EF.Reverse.POCO.v3.ttinclude

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5777,7 +5777,10 @@
57775777
sb.AppendFormat(".HasPrecision({0})", c.Precision);
57785778

57795779
if (c.IsRowVersion)
5780+
{
57805781
sb.Append(".IsRowVersion()");
5782+
c.IsConcurrencyToken = true;
5783+
}
57815784

57825785
if (c.IsConcurrencyToken)
57835786
sb.Append(".IsConcurrencyToken()");
@@ -6076,7 +6079,10 @@
60766079
// sb.Append(".IsMaxLength()");
60776080

60786081
if (c.IsRowVersion)
6082+
{
60796083
sb.Append(".IsRowVersion()");
6084+
c.IsConcurrencyToken = true;
6085+
}
60806086

60816087
if (c.IsConcurrencyToken)
60826088
sb.Append(".IsConcurrencyToken()");
@@ -13085,7 +13091,7 @@ and limitations under the License.
1308513091
col.IsUnicode = !(rt.TypeName == "char" || rt.TypeName == "varchar" || rt.TypeName == "text");
1308613092
col.IsMaxLength = (rt.TypeName == "ntext");
1308713093

13088-
col.IsRowVersion = col.IsStoreGenerated && !col.IsNullable && rt.TypeName == "timestamp";
13094+
col.IsRowVersion = col.IsStoreGenerated && rt.TypeName == "timestamp";
1308913095
if (col.IsRowVersion)
1309013096
col.MaxLength = 8;
1309113097

Generator/Generators/GeneratorEf6.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ protected override void SetupConfig(Column c)
123123
sb.AppendFormat(".HasPrecision({0})", c.Precision);
124124

125125
if (c.IsRowVersion)
126+
{
126127
sb.Append(".IsRowVersion()");
128+
c.IsConcurrencyToken = true;
129+
}
127130

128131
if (c.IsConcurrencyToken)
129132
sb.Append(".IsConcurrencyToken()");

Generator/Generators/GeneratorEfCore.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ protected override void SetupConfig(Column c)
143143
// sb.Append(".IsMaxLength()");
144144

145145
if (c.IsRowVersion)
146+
{
146147
sb.Append(".IsRowVersion()");
148+
c.IsConcurrencyToken = true;
149+
}
147150

148151
if (c.IsConcurrencyToken)
149152
sb.Append(".IsConcurrencyToken()");

Generator/Readers/DatabaseReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ public Column CreateColumn(RawTable rt, Table table, IDbContextFilter filter)
980980
col.IsUnicode = !(rt.TypeName == "char" || rt.TypeName == "varchar" || rt.TypeName == "text");
981981
col.IsMaxLength = (rt.TypeName == "ntext");
982982

983-
col.IsRowVersion = col.IsStoreGenerated && !col.IsNullable && rt.TypeName == "timestamp";
983+
col.IsRowVersion = col.IsStoreGenerated && rt.TypeName == "timestamp";
984984
if (col.IsRowVersion)
985985
col.MaxLength = 8;
986986

TestDatabases/SQLServer/EfrpgTest (manually created).sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,23 @@ INSERT INTO VersionedNullable (Number) VALUES (123);
19281928
INSERT INTO VersionedNullable (Number) VALUES (456);
19291929
GO
19301930

1931+
CREATE TABLE TimestampNotNull
1932+
(
1933+
Id INT NOT NULL IDENTITY(1, 1),
1934+
[Version] TIMESTAMP NOT NULL,
1935+
Number INT NOT NULL,
1936+
CONSTRAINT PK_TimestampNotNull PRIMARY KEY (Id)
1937+
);
1938+
GO
1939+
CREATE TABLE TimestampNullable
1940+
(
1941+
Id INT NOT NULL IDENTITY(1, 1),
1942+
[Version] TIMESTAMP NULL,
1943+
Number INT NOT NULL,
1944+
CONSTRAINT PK_TTimestampNullable PRIMARY KEY (Id)
1945+
);
1946+
GO
1947+
19311948
-- Table with sequences
19321949
CREATE SEQUENCE dbo.CountBy1 AS INT START WITH 1 INCREMENT BY 1;
19331950
CREATE SEQUENCE dbo.CountByBigInt AS BIGINT START WITH 22 INCREMENT BY 234 MINVALUE 1 MAXVALUE 9876543 CYCLE;
1.99 KB
Binary file not shown.

0 commit comments

Comments
 (0)