0

I have a database context with multiple database set. I have an edit (httpget) and an edit (httppost) method. I want to save specific data in specific datasets. How can I specify which database set I want to use? BTW, the view from of the Edit method uses several models.

My database context looks like this:

public class mycontext :DBContext
{
  public DBSet<Table1> table1{get; set;}
  public DBSet<Table2> table2{get; set;}
  public DBSet<Table3> table3{get; set;}
}

When I define

private mycontext data = new mycontext()

The only option is data.SaveChanges(). I want to so something like data.table1.SaveChanges() and pass in the data I want to save.

2
  • 2
    The whole point of the DbContext in Entity Framework is that it keep track of the changes itself, and saves out whatever is needed, all in one transaction, when you call .SaveChanges() on it. You cannot just save half the changes, on one table - all the changes you've made to the context will be saved - all at once Commented Dec 21, 2012 at 16:42
  • Thanks. But say I have a field whose value depend on the button clicked to submit the form and I need to update that field in the table. How will I do that please? Commented Dec 21, 2012 at 18:51

1 Answer 1

1

if you only want to update data in Table1, modify only data in Table1, and then call .SaveChanges()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.