-
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
Net 5 Core Scaffold for SQL Server Calculated Fields doesn't emit ValueGeneratedOnAddOrUpdate() #22545
Comments
@roji Is it possible this was broken at the same time as the other reverse engineering breaks? |
|
@scott452 Are you seeing a functional impact of this? What is not working without this configuration? |
RowVersion also round-trips correctly. |
Yes, without my workaround, I get an error the EF Core code try's to set the value of the field, then SQL server throws an error, saying that the field is a calculated value. |
Share you database design script so we can investigate. |
Will do, here is the error as logged:
|
I have attached 2 database scripts: Azure-ConnectDb-Department-Table.sql Azure-ConnectDB.sql Tables that have the issue all have calculated fields Thanks Scott |
@scott452 - I ran the script to create Department table and scaffolded it. I don't see any missing ValueGeneratedOnAddOrUpdate. Unrelated
entity.Property(e => e.ExtendedName)
.IsRequired()
.HasMaxLength(62)
.HasComputedColumnSql("(([DepartmentCode]+': ')+[Name])", true); Not sure why max length.
entity.Property(e => e.ActiveTo)
.HasColumnType("datetime")
.HasAnnotation("Relational:ColumnType", "datetime"); Using nightly builds. |
@ajcvickers - 2nd issue above is one line fix. Should we do it in rc2? |
@smitpatel Is this a regression from 3.1? |
Also, it's interesting that the column here is "PERSISTED". I assume we don't reverse engineer that facet (yet)? @roji? |
In the Department Table the ExtendedName offending property, it's the one that fires the errors and is fixed by my adding the ValueGeneratedOnAddOrUpdate for the the partial OnModelCreatingPartial(ModelBuilder builder) |
We actually reverse engineer persisted hence 2nd argument of HasComputedColumnSql is true. |
Yes. |
Then yes, we should prepare the PR for rc2. |
@scott452 - The scaffolded code mirrors what database says for value generation and does not look faulty. Can you share how your app is breaking after that scaffolded code? |
Sure, To test the Department Table and Classes, I run my project with two cases. First Case, with this code included in the partial class for the dbcontext and within the
I can create a new Department, no errors Second Case, with that code commented out I get the error that I reported earlier, namely The code that adds the record is exactly the same in both cases:
|
I am not sure this a regression. EF Core 3.1.6:
EF Core 5 RC1:
|
I am actually not even able to repro, when using simpler code than above - this works fine with EF 5 RC1:
|
I was creating a simpler project to try and reproduce my problem. I created a local database with a simple table. The table has a computed field. When I scaffolded the table it generated
This has the HasComputedColumnSql call, the context in my problematic solution did not generate this call, I re-scaffoled the database in my problem child once again, and again it never emitted the call to HasComputedColumnSql for the property. I am stumped, I have checked the both solutions/projects all are using the latest version of the EF packages RC 1. I don't know what is going on. I haven't run the test project yet, but I will bet it will work since it has the call to HasComputedColumnSql Scott |
Multiple databases with differing schema? |
The one that works is local the other in azure, I will check permissions and whatnot. |
Argh, it is a permissions issue, when I scaffold as DBOwner the HasComputedColumnSql call is emitted. |
So nothing is broken now? |
Nope, just my pride. |
@scott452 the user running reverse engineer must have VIEW DEFINITION rights in the database |
Using Net Core RC 1 CLI the command:
dotnet ef dbcontext scaffold Name=ConnectV3Connection Microsoft.EntityFrameworkCore.SqlServer
It doesn't emit
ValueGeneratedOnAddOrUpdate()
for SQL Server calculated fields in the generated OnModelCreating method, nor does it generate an attribute if using the--data-annotations
parameter.For a quick fix I created a partial class for the Context and used the
partial OnModelCreatingPartial(ModelBuilder builder)
method and added the code:entity.Property(e => e.ExtendedName).ValueGeneratedOnAddOrUpdate();
This situation was true for Preview 7 & 8 as well.
Thanks,
Scott
The text was updated successfully, but these errors were encountered: