Take the 2-minute tour ×

With 2 Models in a has-zero-or-one relationship Foo->Bar:

Foo {
    Int FooId
    String Name
    String Address

Bar {
    Int BarId
    Int FooId
    String Favorite

FooViewModel {
    Foo foo;

QUESTION Is it possible on a single form, using EditorFor(fooViewMmodel.foo); EditorFor(fooViewMmodel.foo.Bar); be able to deal with the following logic?

"Is there a associated Bar entry? No? Create it. Yes? Update based on BarId."

Maybe I'm just missing a step in the Controller, but even though the data is passed back the Bar record does not get created.

These are the two lines I thought would take care of things.

db.Entry(fooViewMmodel.foo).State = System.Data.EntityState.Modified;
share|improve this question
The question is a little unclear. Please consider revising. –  evasilchenko Feb 15 '12 at 21:31
Sorry about the confusing wording. Wasn't sure if I was even using the right terminology. –  pmarsh Feb 17 '12 at 16:26
add comment


Your Answer



Browse other questions tagged or ask your own question.