Answered One to one nullable uniqueness

  • Tuesday, March 25, 2008 5:58 PM
     
     
    When I try to change the cardinality property from one to many to one to one between an association on the linq to sql designer I get the following error.

    Cannot create an association "Shopper_Person". Properties do not have matching types: "shopperId", "shopperId".

    Definition as follows, shopperId on Person is nullable but unique and enforced through triggers, which is why it doesn't automatically create the one to one relationship.

    Is this scenario not supported? Or am I just doing something wrong?

All Replies

  • Wednesday, March 26, 2008 9:12 AM
     
     Answered

    Hello,

    The one to one scenario is supported but I think the problem is on your database. Indeed, when you have a one to one relationship, in DB, this means that you have the same PK between the two tables and you have a FK between the two PK. If you do this, you will have a one to one relationship in LINQ To SQL.

    Else, the only thing I think is to extend partial Shopper class and add a property Person which return your

    Code Snippet
    Persons.FirstOrDefault()

     

    with Persons your EntitySet.

  • Wednesday, April 02, 2008 3:31 AM
     
     Proposed

    The fields cannot be nullable.  If you don't want to change your DB for whatever reason you can edit the properties of the member of the class in the .dbml designer.  The downside to this is that the changes will be overwritten if you ever drag and drop the tables onto the design space again.  Another option is to keep the one to many relationship and use the partial classes to add functionality that always returns the first one.

    • Proposed As Answer by Bule Mabuk Sunday, June 07, 2009 6:17 PM
    •