Adding row to relational table - linq to sql
Hello,
I have issue that when I try to add any data in relational table it tries to add that in Primary table to. But Since I already have that record in Primary I get an exception
Here's the scenario.
I have 3 primary Tables - Picture, Album and Collage and two relational table AlbumPicture and CollagePicture.
AlbumPicture and CollagePicture can have same picture but it is not mandatory. Picture in both table can exist independently.
My problem is I have a picture already added in the Picture table and AlbumPicture table. When I try to add this existing picture and new Collage to the CollagePicture table, It throws primry key violation error on PK_Picture. It tries to add picture to picture table and hence the error.
This is what I do
CollagePictures.InsertOnSubmit(new CollagePicture {Collage = CollagePicture = existingPic});
I assign GUID as PK to Picture when Pictures are uploaded. In AlbumPicture I have this pictureId with Album
e.g.
AlbumPictureId [PK] = 1
AlbumId=1
PictureId = 1234567890123456
Now I want to add same Picture (1234567890123456) with Collage. I add this to CollagePicture and it tries to add to the Picture table as well. and that is when I get an exception.
Hope I was clear.
Thanks in advance