you must manually create the view, just like AnatoliiG stated. (Adding index to a table).
You add the name of the view as an attribute to your class
[Table("UserDTO")]
public class UserDTO
{
/* Class code here */
}
You can create an empty migration by specifying the -IgnoreChanges attribute at the end
Add-Migration MigrationName -IgnoreChanges
This gives you an empty migration script that you can manually modify.
You can use your db context to execute your code in your migration 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");
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…