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') image

then from ef core project run image

Result, note .HasComputedColumnSql is there image

Now run with a user that has only db_datareader and db_datawriter: image

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. image

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

Most upvoted comments

@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.