Hello, I am rewriting my application to use the entity framework. What I am confused about is the code I am writing looks like it is making unnecessary tripts the the sql server. For example, I have a question answer site similar to SO. When I add an answer to a question -- here is the code I use:
var qu = context.question.where(c => c.questionID == 11).First(); //Database call here
var answer = new answer();
answer.title = "title here";
answer.desc = "desc here";
answer.question = qu;
context.SaveChanges(); //Database call here
In the code above there are 2 database calls right? If so, why can't I add an answer to a question directly? such as
var ans = answer.Createanswer (0, "title here", "desc here", questionID)
context.SaveChanges();
Is there a way to minimize all the database calls?