I have two tables - Member and Profile with a one to many relationship. I'm trying to insert into the database using LINQ to SQL but am getting a "The INSERT statement conflicted with the FOREIGN KEY constraint" error.
FYI: 1. As this is a practice project to learn LINQ to SQL, I've created my entity classes manually. 2. If I generate the entity classes via designer and try the same operation, it succeeds without error. 3. I generated the code from the DBML using SqlMetal.exe and compared it to my manually created classes. The setup for associations, etc. are exactly the same. Yet my manually created classes don't work. 4. Querying using my manually created classes works fine.
I'm assuming it's not working because it's trying to insert into the child (Profile) table first instead of the parent(Member). But why does it work fine using the auto-generated classes?
This StackOverflow question is similar to my problem, and it doesn't seem to have been answered properly either: http://stackoverflow.com/questions/705716?tab=oldest#tab-top