2
I know it has been asked something similar, but in the answers I found said that to map the view should put the Dataannotation [Table("view name")] or configure in the Fluent API
I created a view in the database called "Users". So I created a class called Userview
[Table("Users")]
public class UserView
{
public string EmailAddress { get; set;}
......
}
Then in my Dbcontext I created Dbset
public DbSet<UserView> Users { get; set; }
When I went around the application I had an error like "The model backing the context has changed Since the database was created."
So in the Nuget Package Console I came in with
Update-Database -force -verbose
Then I had a mistake that there is already an object called "Users". There on the console even showed a "CREATE TABLE USERS ...." IE, he tried to create the table.
I am using Automatic Migrations. How could I map this existing view and/or create it if it does not exist?
Created a
view
in the database?– Jéf Bueno
Yes. I created the direct view in Management Studio
– user26552
Ahhh good, I thought you were confusing view with model (MVC).
– Jéf Bueno
You know that EF will try to create a table in the database and not a view, right?
– Jéf Bueno
I did. I saw in the package console the instruction to create the table.
– user26552