First of all, I apologize: I asked the question whitout being precise. The problem was that, when calling the create function, it gave a null reference exeption on parent.children.add(child):
public actionresult create(parent parent){
child newchild = new (child);
parent.children.add(child);
context.parent.add(parent);
}
The actual problem was that, before the parent is created, the ICollection<child> doesn't exists. It is sufficient to instantiate it before adding elements to it.
this way it works, automatically adding both the parent and the child entities (in the previous example, I also forgot about the context.SaveChanges() instruction to actually save the objects to database):
public actionresult create(parent parent){
child newchild = new (child);
parent.children=new List<child>();
parent.children.add(child);
context.parent.add(parent);
context.SaveChanges();
}</child>
I have a little doubt about the correctness of setting an ICollection to a new List, so if anyone has a better or more correct approach, any suggestion is welcome.