Martin McMahon
Martin McMahon

Reputation: 333

Saving details in a ViewModel

I have a ViewModel I use to create a new user, this updates three different models.

I have a question about how I would edit these details. Looking at examples the edit method in the controller would use something like userRepository.Save(); but for the other items that are in other models other that the User model how would I save them?

Upvotes: 0

Views: 32

Answers (1)

Anri
Anri

Reputation: 6265

You should have DbContext with all the models you are going to update. Calling Save() on that Context's instance will save all the changes.

Like this

public class MainContext : DbContext
{
    public DbSet<User> Users { get; set; }
    public DbSet<Detail> Details { get; set; }
}

Upvotes: 1

Related Questions