-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IsRowVersion and HasConversion<byte[]> produce incorrect migration #22980
Comments
Related: #12436 |
FYI, here is the code I ended up with finally, that currently works well with SQL Server
Property type in model is |
@roji Using |
Actually looking at the code above, I think that none of the But introducing these changes might be somewhat problematic, because Long story short, |
tl;dr this seems to have been fixed in 5.0, I don't see any additional problem to be dealt with. On 3.1, with a byte[] property on SQL Server, no value conversion: RecordVersion = table.Column<byte[]>(rowVersion: true, nullable: true) On 3.1, with a ulong property and value conversion: RecordVersion = table.Column<byte[]>(nullable: false) However, with 5.0.9 the issue is gone and RecordVersion = table.Column<byte[]>(type: "rowversion", rowVersion: true, nullable: false) On SQL Server, if IsRowVersion is specified on a property that isn't a byte[] (or isn't value-converted to one), the column seems to be ignored (e.g. a ulong property with IsRowversion and no value converter gets mapped to |
(adding test in #25998) |
Problem description
I have a property (named
RecordVersion
) ofulong
type, on which I do.IsRowVersion()
and use.HasConversion<byte[]>()
. This is recommended way afaik to have a numeric type in model, butrowversion
in database. When I create migration withadd-migration
in package manager console, invalid migration is generated.In migration file (
20201011132803_Initial.cs
):this is the line that is causing problems:
While if I use
byte[]
type in model class and not use.HasConversion<byte[]>()
, I get slightly different line:It is interesting, that in
MyContextModelSnapshot.cs
, the property is described correctly:What this bug causes
It's also very interesting where this bug manifests itself. Due to missing
rowVersion: true
argument, I'm getting errors when I try to add index to that property! If I use the following for that same property:I get this error:
Column 'RecordVersion' in table 'Master.ProductCategories' is of a type that is invalid for use as a key column in an index.
Code to repro
This is a little too convoluted for this example maybe, but I wanted to provide code as-is. Maybe it has something to do with the fact that I use abstract base class for my entities, or whatever.
This is entity:
In
OnModelCreating
I enumerate each property withRowverAttribute
and do on them:and:
Verbose output
This is the error I get after
update-database -verbose
:Provider and version information
EF Core version: 3.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.1
Operating system: Win 10 latest
IDE: Visual Studio 2019
Other info
I think this might be somewhat related to #12434, but I decided to create separate issue, because the wording in there is not too clear for me, and also this particular case has maybe some interesting details (like it messes when you create index on that
rowversion
, but works otherwise).The text was updated successfully, but these errors were encountered: