You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using an entity with a property with a type different from byte[] that is configured as a RowVersion, the migration generated doesn't specify that the column should be a rowversion, and instead just creates a byte array column on SQL Server. This happens even if the property has a valid conversion to byte[] (like ulong).
Steps to reproduce
This is the simplest repro I could create. You can recreate the migration to verify the problem.
Will not generate a migration that indicates that the RowVersion column should be a rowversion from SQLServer.
This is the relevant part from the generated migration:
migrationBuilder.CreateTable(name:"Entities",columns: table =>new{// notice the missing rowVersion: trueRowVersion=table.Column<byte[]>(nullable:false)}
If you change the property to be a byte[] in the C# mapped entity, it starts generating the migration correctly again.
I believe the problem is this check, since EF core corrctly understands the ulong to byte[] conversion and works perfectly when querying or in CRUD operations, I believe this check shouldn't ignore the IsRowVersion mapping info based on the assumption that only a property with a byte[] type is valid.
Properties with a valid conversion to byte[] should also be considered when setting the rowVersion flag.
Workaround
As a workaround, we are using the .ColumnType("rowversion"), but this is not valid in all scenarios, since if you decide to "fix" the issue making the property a byte[], EF Core won't understand something has changed, generating an empty migration. So if you apply a faulted migration, undoing the mistake is not as simple as generating a new migration from ef core.
Further technical details
EF Core version: 3.1.1. But confirmed to happend at least since 2.1.14
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.1
Operating system: Windows and Mac
IDE: Visual Studio 2019 16.3.1
The text was updated successfully, but these errors were encountered:
@akamud Thanks for the detailed issue; I think this is essentially a duplicate of #12434 but we will revisit the priority.
but this is not valid in all scenarios, since if you decide to "fix" the issue making the property a byte[], EF Core won't understand something has changed, generating an empty migration.
I don't think EF should be creating an empty migration here. Can you file a new issue for this?
When using an entity with a property with a type different from
byte[]
that is configured as a RowVersion, the migration generated doesn't specify that the column should be arowversion
, and instead just creates a byte array column on SQL Server. This happens even if the property has a valid conversion tobyte[]
(likeulong
).Steps to reproduce
This is the simplest repro I could create. You can recreate the migration to verify the problem.
This entity:
With this configuration:
Will not generate a migration that indicates that the
RowVersion
column should be arowversion
from SQLServer.This is the relevant part from the generated migration:
If you change the property to be a
byte[]
in the C# mapped entity, it starts generating the migration correctly again.I believe the problem is this check, since EF core corrctly understands the
ulong
tobyte[]
conversion and works perfectly when querying or in CRUD operations, I believe this check shouldn't ignore theIsRowVersion
mapping info based on the assumption that only a property with abyte[]
type is valid.Properties with a valid conversion to
byte[]
should also be considered when setting therowVersion
flag.Workaround
As a workaround, we are using the
.ColumnType("rowversion")
, but this is not valid in all scenarios, since if you decide to "fix" the issue making the property abyte[]
, EF Core won't understand something has changed, generating an empty migration. So if you apply a faulted migration, undoing the mistake is not as simple as generating a new migration from ef core.Further technical details
EF Core version: 3.1.1. But confirmed to happend at least since 2.1.14
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.1
Operating system: Windows and Mac
IDE: Visual Studio 2019 16.3.1
The text was updated successfully, but these errors were encountered: