efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Improved view support

Open ilmax opened this issue 12 years ago • 48 comments

This is a grouping of related issues. Feel free to vote (👍) for this issue to indicate that this is an area that you think we should spend time on, but consider also voting for individual issues for things you consider especially important.


This is a meta-issue covering the different aspects of support for mapping to and using views in EF Core.

Done in 2.1

  • [x] #9290
  • [x] #1862

Done in 3.0

  • [x] #1679

Done in 5.0

  • [x] #17270
  • [x] #15671
  • [x] #480

Done in 7.0

  • [x] #245

Done in 8.0

  • [x] #10753

Backlog

  • [ ] #14537
  • [ ] #20940

Please consider voting :+1: for one of the issues above rather than for this overall issue, since that will provide more specific and actionable feedback about the relative importance of different aspects of view support.


Original issue text:

Hi, I have prototyped a really basic (or even less) view support through part of the EF Core stack, currently my prototype is able to

  • Map entity to a View via fluent api
  • Create a view via migrations
  • Read and materialize values backed by views
  • Avoid updating entities if backed by views

As stated above, this is a really naive approach and I know there are a tons of unsupported features at the moment, anyway I really would like to improve this further and I would be glad to discuss implementation details with the EF team and the community.

I would like to know if the EF team are interested in this contributions. Thanks, Max.

ilmax avatar Oct 08 '14 20:10 ilmax

@ilmax - At this early stage of the project this isn't something we want to take just yet (as we're still heavily iterating on the core of the product). You could do this as an external add-on to EF and we would definitely be open to considering taking it a little further down the road.

rowanmiller avatar Oct 10 '14 20:10 rowanmiller

Hi @rowanmiller, does the team is interested in such contribution? I would like to be able to query views with EF, and would love to give my contribution on this feature.

If this is something the team can be interested in, I would like to start a discussion around the needed changes and the general direction to take.

Regards, Max.

ilmax avatar Apr 17 '15 20:04 ilmax

I agree with Max, this would be an excellent feature. It would be even cooler if we could use linq to define indexed views.

milutinovici avatar May 06 '15 10:05 milutinovici

Without view support EF Core is almost useless as, I'm sorry to say, the query generator does not have enough intelligence for supporting high performant business applications with 10 or more joins, unions and complex "group by" statements on applications with millions of records. And some databases just all ready have good views on board. ICT work is often about modernizing gui's on old databases. And we don't want to use raw sql to be able to get a 1-to-1 mapping of views/viewmodels. Please do support views and updatable views by -self defining- keys in metadata as we now have to use 6.x isnull/nullif and 'editing the edmx after each update' workarounds.

rogerhendriks avatar May 10 '15 12:05 rogerhendriks

@ilmax care to share how you are mapping views and generating migrations for them?

staff0rd avatar Sep 19 '15 03:09 staff0rd

@staff0rd my prototype was build against early EF Core version, since ef was in the early days at the time, I abandoned the prototype, waiting for EF Core to RC. I think that now the majority of EF building blocks are quite stable, so maybe I can start working on this and put together a prototype here on github.

ilmax avatar Sep 19 '15 09:09 ilmax

@ilmax any update, EF Core is RC already... :) I would really be happy using this feature.

gdoron avatar Feb 13 '16 19:02 gdoron

@gdoron Since EF Core is a completely new rewrite, over the time a lot of parts have changed so my POC is not working anymore, I plan to work on this as soon as EF Core reaches RTM

ilmax avatar Feb 15 '16 09:02 ilmax

@ilmax I think since EF is RC already there won't be as much changes as when it was Alpha/beta.

But regardless, once you contributed the code and it was merged, it's in the repository, and if the EF team will do a breaking change that break the view generation (not a likely scenario since RC), they will have to fix it, so I wouldn't be too much worry about it.

gdoron avatar Feb 15 '16 10:02 gdoron

BTW in the meantime you can just tell EF that the view is a table. The limitations of this approach are that you need to give EF some properties to use as a key, and migrations won't create a view for you. You can also use raw SQL to select from a view context.Blogs.SqlQuery("SELECT * FROM dbo.TopBlogsView").

rowanmiller avatar Feb 16 '16 17:02 rowanmiller

But regardless, once you contributed the code and it was merged, it's in the repository, and if the EF team will do a breaking change that break the view generation (not a likely scenario since RC), they will have to fix it, so I wouldn't be too much worry about it.

This is true, but the feature needs to be completely implemented (including tests etc.) for us to take the code.

rowanmiller avatar Feb 16 '16 17:02 rowanmiller

@rowanmiller but how can I trick EF not to try and create the table (which is a view) in the migrations? Manually remove the creation from the migration?

context.Blogs.SqlQuery("SELECT * FROM dbo.TopBlogsView").

This will work only if the view returns data from a single table, if it's (like in 99% of the times) a view that returns data from multiple composed tables, we'll get only the data from the Blogs, the columns from Users let's say will be ignored when deserialized.

in the meantime you can just tell EF that the view is a table

You reminded me an old jewish joke I heard 10 years ago. :)

gdoron avatar Feb 16 '16 18:02 gdoron

but how can I trick EF not to try and create the table (which is a view) in the migrations? Manually remove the creation from the migration?

Yes, that is what you would need to do

rowanmiller avatar Feb 16 '16 18:02 rowanmiller

@rowanmiller I don't see VIEWs support in the roadmap at all. Do you really consider it be in in such a low priority that all the stuff in the roadmap are more important than VIEWs or you simply forgot to mention it?

Thanks

gdoron avatar May 17 '16 17:05 gdoron

We just missed it off the list, I've added it to the roadmap.

rowanmiller avatar May 17 '16 17:05 rowanmiller

@rowanmiller You might want to add a link in the roadmap to this PR for how it can be done in the meanwhile: #4561 so people won't think there's absolutely no way of doing it.

Thanks

gdoron avatar May 17 '16 17:05 gdoron

@rowanmiller great to see it's on the roadmap! Kutgw

rogerhendriks avatar May 18 '16 17:05 rogerhendriks

Has this issue been targeted for a release yet?

We are currently having to maintain two database catalogs for code generation. We have one database that contains table schema only to represent the views that exist in our actual database.

Vance

vcannaday avatar Oct 26 '16 17:10 vcannaday

Happy this is on the roadmap, it's hard to justify EF Core usage without DBFunctions and views.

douglasg14b avatar Dec 25 '16 22:12 douglasg14b

Do you have any release date for supporting views?

AxelDalenAndersenP avatar Jan 28 '17 07:01 AxelDalenAndersenP