locked
Dilemma over 1 to 0..1 association. RRS feed

  • Question

  • Why does a one to one association created in database always shown  as 1 to 0..1 in edmx. Can anyone help me out please.

    I have tableA with Id as a primary key,  tableB with Id as primary key and it has a foreign key constraint too. Doesn't that make a 1 to 1 association in database.

    • Edited by swainjena Sunday, April 22, 2012 1:39 PM
    Sunday, April 22, 2012 4:05 AM

Answers

  • Hi swainjena,

    Welcome to MSDN Forum.

    The relationship you created is 1 to 0..1. Try to insert a record in tableA, and don't insert anything in tableB, you will find it can success. So after you create the edmx file in Entity Framework, the relationship of the two entities is one to zero or one.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Allen_MSDN Friday, April 27, 2012 2:24 AM
    Tuesday, April 24, 2012 5:47 AM

All replies

  • If you want to create one to one, the two tables' primary keys need also be foreign keys. I think you may only set one primary key as a foreign key, so it will shown as one to zero or one.

    Fighting like Allen Iverson. Neve give up!

    Sunday, April 22, 2012 11:52 AM
  • How would you do that ? Could you please elaborate.
    Sunday, April 22, 2012 1:39 PM
  • Hi swainjena,

    Welcome to MSDN Forum.

    The relationship you created is 1 to 0..1. Try to insert a record in tableA, and don't insert anything in tableB, you will find it can success. So after you create the edmx file in Entity Framework, the relationship of the two entities is one to zero or one.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Allen_MSDN Friday, April 27, 2012 2:24 AM
    Tuesday, April 24, 2012 5:47 AM