-
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
Scaffold annotations on DatabaseModel to the generated model #6561
Comments
I have something different on this topic to report. I use the --data-annotations option when running, and I can't figure out what's different about the table definitions that might cause it to do that. As I'm writing this, the only difference I can think of is that the table which does end up with the [Key] has its primary key field named "ID" while the other one's don't. But I can manually put [Key] in another table class and have it work. |
@codearoo I can think of two cases in which we wouldn't generate the
|
Well if it was by convention, then I would not expect it to also output the Fluent code that defines the key. However, exactly the reverse of what you described, a table with a field ID had the [Key] attribute generated while no other table did. But I manually changed them (the ones that have just 1 key field) and it works fine. Are there plans to allow composite keys with the [Key] attribute? |
@codearoo Thanks for clarifying. Could you please create a new issue and fill in the details of any surprising behavior you are seeing? Although the title of this issue contains the word "scaffold" and "annotations", it is about something completely different. |
@smitpatel fixed this in #8680 |
With the recent work on provider-specific migrations operations via annotations (e.g. PostgreSQL extensions), I took a look at scaffolding as well. The goal here would be to detect PostgreSQL extensions present in an existing database and scaffold them into the generated model's
OnModelCreating
.Looking at
DbContextWrite.AddOnModelCreating
, I can't see any code dealing with annotations on DatabaseModel. For example, it doesn't seem possible for scaffolded models to haveDefaultSchema
set. I hope I'm not missing something.A first step here would be for
AddOnModelCreating
to simply generate code for all annotations it finds on the model itself. A special case could be made for default schema (and others?), generating the prettierHasDefaultSchema
rather than doing it via the generic annotation API. Once #6546 is done, it could be used in the scaffolding pipline as well to allow providers to replace generic (and ugly) annotations with provider-specific renderings.This is really not an urgent feature - I'm sure you have more important things to do - but I wanted to put it out there and make sure I'm not missing something.
The text was updated successfully, but these errors were encountered: