#Creating a SQL View w/ Entity Framework
- Create an entity with the proper format (matching the columns, properties, etc., of your SQL View).
- Add an entry to your
DbContext
similar to any other entity; e.g.public DbSet<MyView> MyViews { get; set; }
- Run
Add-Migration CreateMyViews
(name is irrelevant, but try to describe what you're doing: Creating a new view). - Alter the migration so that it instead creates your SQL view,
Sql(@"create view MyView as (your select here)");
- Note: put a
@
before your string to allow it to run along multiple lines
- Run
Update-Database -Force