Adding the ViewModel class adds the codefirst model to the database

I need a view model in my ASP.NET MVC 5 project, but when I added it to the models folder, a new entity was added to the database, and I had to add the migration and update my database. I do not want this to happen, as it is a view model that I am adding, not a model that I need to store in the database. I want to raise some of the controllers and views, so I added the primary key to the class. I did not add the newly created view model to the class DbContext.

ViewModel:

    public class RolesViewModel 
    { 
        public int RolesViewModelId { get; set; }
        public string Role { get; set; } 
    }

Is there a way to create a view model that is not automatically added to the class DbContextand therefore leads to a change in the data model?

Many thanks,

Jason

+4
1

, .. . , , . DbContext, , -, . " ", , - , DbContext, , - , , " ", . , DbContext.

+6

Source: https://habr.com/ru/post/1530880/


All Articles