tags:

views:

32

answers:

1

Hey, I have two tables: ScheduledEvent and DrawSequence. The ScheduledEvent table has zero or one DrawSequence entries. The PK of the ScheduledEvent is an identity integer which is used in a FK from DrawSequence.

I have created by dbml file, generated the classes and it shows the parent (ScheduledEvent) has an EntitytRef to the child (DrawSequence).

When I create a new parent and set its child to a new DrawSequence and save it, the child's FK field is not set to the parent's newly allocated PK.

I have googled this and found nothing that helps. if you have any ideas, I'd greatly appreciate it.

I've added the change log after this:

INSERT INTO [dbo].[ScheduledEvent]([StartDate], [EndDate], [Ongoing], [Active], [ScheduledEventName], [LastUpdated], [LastUpdatedUser])
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6)

SELECT CONVERT(Int,SCOPE_IDENTITY()) AS [value]
-- @p0: Input DateTime (Size = 0; Prec = 0; Scale = 0) [11/03/2010 12:00:00 AM]
-- @p1: Input DateTime (Size = 0; Prec = 0; Scale = 0) [11/03/2010 12:00:00 AM]
-- @p2: Input Bit (Size = 0; Prec = 0; Scale = 0) [False]
-- @p3: Input Bit (Size = 0; Prec = 0; Scale = 0) [False]
-- @p4: Input NVarChar (Size = 4; Prec = 0; Scale = 0) [ssss]
-- @p5: Input DateTime (Size = 0; Prec = 0; Scale = 0) [11/03/2010 5:22:04 PM]
-- @p6: Input NVarChar (Size = 10; Prec = 0; Scale = 0) [TODO: fred]
-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30729.1

INSERT INTO [dbo].[DrawSequence]([ScheduledEventID], [SendEmails], [EmailAdds], [SendPages], [PageNums], [IsInstantDraw], [InstantDrawRunDate])
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6)

SELECT CONVERT(Int,SCOPE_IDENTITY()) AS [value]
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [0]
-- @p1: Input Bit (Size = 0; Prec = 0; Scale = 0) [False]
-- @p2: Input NVarChar (Size = 0; Prec = 0; Scale = 0) []
-- @p3: Input Bit (Size = 0; Prec = 0; Scale = 0) [False]
-- @p4: Input NVarChar (Size = 0; Prec = 0; Scale = 0) []
-- @p5: Input Bit (Size = 0; Prec = 0; Scale = 0) [True]
-- @p6: Input DateTime (Size = 0; Prec = 0; Scale = 0) [Null]
-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30729.1
A: 

Maybe your mapping is not correct, did you check that the parents PK is set as Identity and Auto-generated? Normally L2S would SELECT Scope_Identity() after the first one and pass that to the second insert.

Johannes Rudolph
Thanks for responding. I've checked and the parent PK seems fine. The output above shows that it was reading back the identity. I am leaving this job in 1 hour 7 minutes so I suppose someone else will have to deal with the problem.
dave