I have a really odd problem.
I have 3 tables.
- Positions
- PositionAttachments
- Attachments
I won’t bore you with the keys and foreign keys as that should be kinda evident.
If I add a new position, attachment and positionattachment all’s well.
If I add a new attachment to an existing Position record i get the following.
- Positions table is updated and I can see changes on screen
- Attachment table has new record
- PositionAttachments table has new record
- New Attachment does not appear on screen within my application
- Close application, recompile and re run and I have the same as 4
- View ANY table through SQL server and I get kicked out of my session and once I log back in I see the records on screen.
At no point is there an error being generated.
Update record code;
public void AddAttachmentToPosition(PositionsAvailable positionModel, Attachment attachment)
{
//attachment.id = Guid.NewGuid();
dc.Attachments.InsertOnSubmit(attachment);
PositionAttachment positionAttachment = new PositionAttachment();
positionAttachment.PositionId = positionModel.PositionId;
positionAttachment.AttachmentId = attachment.id;
//positionAttachment.id = Guid.NewGuid();
dc.PositionAttachments.InsertOnSubmit(positionAttachment);
dc.SubmitChanges();
}
Edit
I have looked at the log produced by the Data context and I get this for the PositionAttachments insert. It looks essentially the same for the Attachments table.
DECLARE @output TABLE([id] UniqueIdentifier)
INSERT INTO [dbo].[PositionAttachments]([PositionId], [AttachmentId])
OUTPUT INSERTED.[id] INTO @output
VALUES (@p0, @p1)
SELECT [id] FROM @output
-- @p0: Input UniqueIdentifier (Size = 0; Prec = 0; Scale = 0) [92a3627d-ad01-466e-a315-423c851efc5d]
-- @p1: Input UniqueIdentifier (Size = 0; Prec = 0; Scale = 0) [db566728-a313-40c7-af82-0a2f147234eb]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 3.5.30729.5420
To my mind, this looks pretty normal. And besides, the same code works when I am adding a new Position just not when I am adding attachments to an existing position.
Just a hunch, what if you try:
Although I think the DC should also pick up the ID’s properly