locked
EF4: 1 <-> 0..1 in Model Design Mode RRS feed

  • Question

  • Hi

    I use the model first approach and generate a database from it. Now i have following situation:

    Parent (1) <--> (0..1) Child

    EF4 makes (1) <--> (*) of it ...

    Parent: Id, Name
    Child: Id, Name and Navigation Property to Parent

    How can i make a real (1) <--> (0..1) association?

    Thanks a lot
    Michael 

     

    Sunday, September 18, 2011 10:15 AM

Answers

  • Hi Michael,

    You could try to right-click one entity in model, and select Add and then Association, in the pop-up window, you could set set the relationship between two entities. You also could select generate a new unique FK, and I think this way is good to you.

    I hope this can help you.

     

    Have a nice day,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jackie-Sun Monday, September 26, 2011 6:14 AM
    Tuesday, September 20, 2011 2:52 AM

All replies

  • Hi,

    0..1 is enforced by having a unique key on the fk column (which is likely the only difference with 0..n). Double check the db but you should have a unique index on the Parent column in your Child table.

    Else please be more explicit about what you expected.


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    Sunday, September 18, 2011 11:44 AM
  • Hi

    Thanks. My problem is how to add the FK column in Model designer (edmx). How can i do that?

    Thanks

    Michael 

    Sunday, September 18, 2011 3:57 PM
  • Hi Michael,

    You could try to right-click one entity in model, and select Add and then Association, in the pop-up window, you could set set the relationship between two entities. You also could select generate a new unique FK, and I think this way is good to you.

    I hope this can help you.

     

    Have a nice day,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jackie-Sun Monday, September 26, 2011 6:14 AM
    Tuesday, September 20, 2011 2:52 AM
  • Thx - it works :-)

    Regards
    Michael

    Tuesday, September 27, 2011 5:33 AM