Data Platform Developer Center > Data Platform Development Forums > ADO.NET Entity Framework and LINQ to Entities > "A relationship is being added or deleted from an AssociationSet" Foreign Key Issue on Update
Ask a questionAsk a question
 

Answer"A relationship is being added or deleted from an AssociationSet" Foreign Key Issue on Update

  • Monday, June 08, 2009 5:15 AMboyongoo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I'm working with EF in a detached fashion because I'm using WCF services. I'm having trouble setting a foreign key reference when updating the entity (add works fine.)

    The code - http://pastebin.com/d4f69895d

    On db.SaveChanges() - it throws the exception - "A relationship is being added or deleted from an AssociationSet 'FK_Users_CarrierId'. With cardinality constraints, a corresponding 'Users' must also be added or deleted."

    Here's how I add the carrier reference:

    entity.CarrierReference.EntityKey =

    new EntityKey("CouponEntities.Carrier", "CarrierId", user.Carrier.Id);

    How do I fix this exception? Dealing with foreign keys seems to not be so much fun in EF...

    Thanks,
    Justin

Answers

  • Saturday, June 13, 2009 6:19 PMboyongoo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    I think the answer is that EF just sucks right now. Switched back to Linq to SQL for the time being...
    • Marked As Answer byboyongoo Saturday, June 13, 2009 6:19 PM
    •  

All Replies