you must manually create the view, just like Anatoly said. ( Adding an index to the table ).
You add the name of the view as an attribute to your class
[Table("UserDTO")] public class UserDTO { }
You can create an empty migration by specifying the -IgnoreChanges attribute at the end
Add-Migration MigrationName -IgnoreChanges
This gives you an empty script migration that you can change manually.
You can use your db context to execute code in your wrapper script
public partial class editUserDTO : DbMigration { public override void Up() { string script = @" CREATE VIEW dbo.UserDTO AS SELECT p.PersonId AS UserId, p.FirstName, p.LastName, u.UserName FROM dbo.Users u INNER JOIN dbo.People p ON u.PersonId = p.PersonId"; BloggingContext ctx = new BloggingContext(); ctx.Database.ExecuteSqlCommand(script); } public override void Down() { BloggingContext ctx = new BloggingContext(); ctx.Database.ExecuteSqlCommand("DROP VIEW dbo.UserDTO"); } }
Fred Sep 09 '13 at 21:35 2013-09-09 21:35
source share