Skip to content
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

Support updatable views #20013

Closed
Tracked by #827
AndriySvyryd opened this issue Feb 21, 2020 · 4 comments
Closed
Tracked by #827

Support updatable views #20013

AndriySvyryd opened this issue Feb 21, 2020 · 4 comments
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed.

Comments

@AndriySvyryd
Copy link
Member

Split off #17270

Would be configured using something like .ToView(updatable: true) and would be used instead of the configured table for CUD operations.

@pfdsilva
Copy link

pfdsilva commented Jun 17, 2020

@AndriySvyryd @ajcvickers @JeremyLikness
Please could you confirm if updating of rows is not supported when an entity class is mapped to a view using fluent API?

I have the following code in my OnModelCreating method.

 modelBuilder.Entity<BlogsView>(entity =>
            {
                entity.ToView("BLOGS_VIEW");

                entity.Property(e => e.Id)
                    .HasColumnName("ID")
                    .HasColumnType("NUMBER(38)");

                entity.Property(e => e.Sub)
                    .HasColumnName("SUB")
                    .HasColumnType("VARCHAR2(30)");
            });

When I execute the following code from my Main method, I am noticing that the changes are getting successfully reflected on the database. I was expecting that the update will not go through because I thought updating of views from EFCORE is not supported. May be I have not understood the scope of this github issue. Please could you help me understand?

var entity = db.BlogsView.FirstOrDefault(item => item.Id == 10);

          // Validate entity is not null
          if (entity != null)
          {
            // Make changes on entity
            entity.Id = 10;
            entity.Sub = "new sub";
          }

I am using an Oracle DB and the view that I have created on the DB has a primary key constraint on the Id column of the view.

Other Info:
I am using Microsoft.EntityFrameworkCore (3.1.5) and Microsoft.EntityFrameworkCore.Relational (3.1.5)

@AndriySvyryd
Copy link
Member Author

@pfdsilva In 3.1.5 SaveChanges doesn't differentiate between views and tables, so it will try to update whatever is configured. In 5.0 you'll be able to map an entity type to both a view and a table and SaveChanges will only use the table mapping

@ajcvickers ajcvickers removed this from the Backlog milestone Nov 10, 2021
@ajcvickers ajcvickers added the closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. label Mar 10, 2022
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
@johnwc
Copy link

johnwc commented Apr 4, 2023

@AndriySvyryd When using scaffolding, there is no way to tell it to use ToTable(...) instead of ToView(...) What do we do in that scenario?

@ErikEJ
Copy link
Contributor

ErikEJ commented Apr 4, 2023

@johnwc You may be able to set it ToTable and specify a Key in a partial class that implements the OnModelCreatingPartial method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed.
Projects
None yet
Development

No branches or pull requests

5 participants