-
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
EntityTypeBuilder ToView or not ToView #14787
Comments
Notes from triage: we will not obsolete |
See also #2725 |
Extract from #1679 (comment):
I think it is fair to say that EF Core tries to abstract common aspects of databases to enable customers to write code that queries and persists data in terms of entities, typically using a DbContext.
I think it is true that at the database level tables and views can be used pretty much interchangeably (views may be more often read-only or have no keys, but we know that is not universally true, and I think we are all mostly in agreement that conflating these concepts was a bad idea). The actual difference between tables and views is in how they are defined: while tables represent named storage areas with a specific schema, views are named virtual tables based on queries over other tables or views. In alignment with all of this, our plan for EF Core 3.0 is that entities configured to map to views will have the exact same query and persistence capabilities as entities mapped to tables. The only difference between ToView and ToTable will be in what migrations and EnsureCreated will do with them:
Ideally EF Core migrations and EnsureCreated should have the capability to create views instead, but for now that is not the case. We are missing migrations operations that represent DDL for views, and an API to associate a defining query with the view. Given this limitation, migrations and EnsureCreated will have to simply ignore (not try to create any DDL) for any database object introduced to the model with ToView. And this is where I have my actual concerns with ToView: If someday we want to add the capability to create database views, an argument providing a defining query for the view would be required, but is it ok to just implicitly ignore the object if it isn’t provided? I think the connection between the ToView method and the behavior (database object is to be ignored by migrations and EnsureCreated) becomes too implicit and obscure. E.g.:
That might work, but would it really be ok? It reminds me of the kind of thing that happens when we make it too easy to conflate orthogonal concepts, e.g. when customers started trying to use the Query<T> API with tables that they wanted to treat as read-only, even if they had primary keys defined. |
Discussed this again and per @divega's comments we are not going to make this change. We may bring |
I had another idea that I like more because I believe it helps us keep a simple version of
Hence the simple version of Reopening so that we can discuss this again. Sorry about the randomization. |
Triage: will discuss with @bricelam |
After lengthy discussion on whether or not this would make the experience better we are going to punt for 3.0, and leave |
Open questions: What should migrations do with keyless entity types? Should calling ToView (obsolete) affect that behavior? |
For 3.0:
We also need to follow up on reverse engineering:
|
@bricelam does this mean adding a bool IsView to the Table class in DatabaseModel then? |
Yep, or at least some way to tell the difference |
Also worth thinking about where we’ll eventually put the view definition SQL |
@ErikEJ I'm adding a DatabaseTable sub-type--DatabaseView--instead, so we can add things like ViewDefinition and IsUpdatable later. |
Should it remain obsoleted or become a permanent synonym for
ToTable
?The text was updated successfully, but these errors were encountered: