How to create Indexed Views with entity framework code-first approach

2.9k Views Asked by At

I have a 3 tables which need to be joined for doing some queries. The tables are relatively read-only for specific duration of time. Only if there is need, we need to write them.

I want to avoid join on demand for these tables. So I was planning to use Indexed views. However, I didn't find a way to define a view from entity framework (EF 6.1).

Can someone please guide on this?

Regards, Amit Rangari

2

There are 2 best solutions below

0
On

There is no direct method for creating views from EF 6.

You need to write raw SQL to create the view, then execute it from a dbMigration. For details see: https://msdn.microsoft.com/en-us/magazine/dn519921.aspx

0
On

You need to create the view via standard SQL statement (migration or the connection of the context). The view should have a key. After that you can map the view with EF like it was a table.