efcore: dotnet ef dbcontext scaffold doesn't work with computed columns unless user is db_owner
To reproduce:
Create a new DB called TestDB, add table Table_1, add column “test” make primary key, run alter table Table_1 add CalcField as (test + 'test-o-rama')
then from ef core project run
Result, note .HasComputedColumnSql
is there
Now run with a user that has only db_datareader and db_datawriter:
Everything still scaffolds, and there is no error, but the .HasComputedColumn
is gone, which really messes things up when trying to write back to the database since EF now tries to overwrite that column resulting in errors.
One would think that db_datareader would either be enough to scaffold correctly, or an error would throw. It would be vastly preferable to not have to give everyone db_owner if they need to scaffold the DB.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 21 (16 by maintainers)
Commits related to this issue
- Log warning when credentials used for reverse enigineering does not have view definition rights (#26776) fixes #22842 — committed to dotnet/efcore by ErikEJ 3 years ago
@ErikEJ Warning is fine.
I think @ErikEJ did similar investigation for some other issue.
If whatever permission user has is not enough for us to get required data then schema generated will be based on data we got from server.