Skip to content

Materialised views #20858

@TehWardy

Description

@TehWardy

I've been following the discussion on #1368 for some time and I just had a thought that might be good for some "complex" scenarios.

SQL Servers have the concept of a "materialised view" which is basically a regular view but with some added ability to map that back to the source fields, meaning you can interact with it just like a regular table.

Given that the implementation of Many-To-Many joins when completed will ultimately involved some abstraction or proxying or mapping within the model so that for example ...

"UserRoles" is a hidden join that exists in the db but not in the exposed entities instead many "Users" each have a collection of many "Roles" and the same is true the other way, (a-la EF6 way of handling the join).

Given this will require some mapping and abstraction, could we do something like this using the same API ...

Typical example ...

I have tables for Invoices and for Credits and for Payments.
They all derive from a common "Transaction" type which for now I have told EF to ignore.

It would be really cool if I could say to EF "Build me an entity set " which is defined from this "aggregation / mapping set" and when I interact with that set EF deals with the mapping back to the source tables from where the complex set got the data automatically.

In my case I could expose "Transactions" as such a set and insert Invoices or Credits or Payments in to that set and context would map that back to the correct destination table for me, with of course "full CRUD" supported as per the usual expectation on EF Set even if I have to declare it as ComplexSet or something and do some wiring up.

Under the bonnet, EF could use (for SQL server) a Materialised View, or it could do the whole lot in memory, that's an implementation detail I guess the framework would solve.

For me ... the net benefit here is that I could provide aggregations or complex reports and leverage the framework / underlying DB servers features to optimise the performance of some complex scenarios that today would involve say ... a very long OData query or a complex LINQ query in my business logic that I have to marry up sets of data prior to my aggregation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions