Hello,
S.O.S...
I have 2 tables, Slip and Slipassociate. Relationship is...
Slip.SlipId to SlipAssociate.SlipId and
Slip.SlipId to SlipAssociate.AssociateSlipId, i.e. both IDs on the associate link back to the same field on slip.
Both the slipAssociate FK's do not allow NULLS.
This happens in a UOW:
SlipassociateEntity slipassociateEntity = new SlipassociateEntity();
slipassociateEntity.Slipid = slip.SlipcodeId;
slipassociateEntity.AssociateSlipid = slip.SlipcodeId;
slip.Slipassociate.Add(slipassociateEntity);
You don't need to set the FK value (which is SlipAssociateEntity.SlipId above) manually as it will automatically be set by LLBLGen, right? (Due to relation)
Problem is I am getting an "INSERT statement conflicted with FK constraint"?
Generated Sql query:
Query: INSERT INTO [company].[dbo].[tblSLIP] ([CompanyID], [SLIPCode], [SLIP], [GLCodeID], [SLIPTypeID], [SLIPScopeID], [SLIPCost], [SLIPPercent], [TaxId], [CCMID], [MinCalcCost], [MinCalcPercent], [PrintNoticeCost], [BudgetBillOptionID], [IsActive], [UserAltered], [EffectiveDate], [ExpiryDate]) VALUES (@CompanyId, @Slipcode, @Slip, @GlcodeId, @SliptypeId, @SlipscopeId, @Slipcost, @Slippercent, @TaxId, @Ccmid, @MinCalcCost, @MinCalcPercent, @PrintNoticeCost, @BudgetBillOptionId, @IsActive, @UserAltered, @EffectiveDate, @ExpiryDate);SELECT @SlipcodeId=SCOPE_IDENTITY()
Parameter: @SlipcodeId : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Output. Value: <undefined value>.
Parameter: @CompanyId : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 1.
Parameter: @Slipcode : String. Length: 6. Precision: 0. Scale: 0. Direction: Input. Value: "111111".
Parameter: @Slip : String. Length: 25. Precision: 0. Scale: 0. Direction: Input. Value: "1111111111111111111111111".
Parameter: @GlcodeId : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 4.
Parameter: @SliptypeId : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 2.
Parameter: @SlipscopeId : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 2.
Parameter: @Slipcost : Decimal. Length: 0. Precision: 15. Scale: 5. Direction: Input. Value: 2.
Parameter: @Slippercent : Decimal. Length: 0. Precision: 11. Scale: 5. Direction: Input. Value: 3.
Parameter: @TaxId : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 32.
Parameter: @Ccmid : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 2.
Parameter: @MinCalcCost : Decimal. Length: 0. Precision: 15. Scale: 5. Direction: Input. Value: 5.
Parameter: @MinCalcPercent : Decimal. Length: 0. Precision: 11. Scale: 5. Direction: Input. Value: 5.
Parameter: @PrintNoticeCost : Decimal. Length: 0. Precision: 15. Scale: 5. Direction: Input. Value: 5.
Parameter: @BudgetBillOptionId : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 1.
Parameter: @IsActive : Boolean. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: True.
Parameter: @UserAltered : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 3.
Parameter: @EffectiveDate : DateTime. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 13/03/2008 11:46:26 AM.
Parameter: @ExpiryDate : DateTime. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 13/03/2008 11:46:26 AM.
...followed by...
Generated Sql query:
Query: INSERT INTO [company].[dbo].[tblSLIPAssociate] ([SLIPID], [AssociateSLIPID]) VALUES (@Slipid, @AssociateSlipid);SELECT @SlipassociateId=SCOPE_IDENTITY()
Parameter: @SlipassociateId : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Output. Value: <undefined value>.
Parameter: @Slipid : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 54.
Parameter: @AssociateSlipid : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 0.
It is setting the Slipid correctly, but the AssociateSlipid which should be set in exactly the same way is being sent through as 0 for some reason?
slipassociateEntity.Slipid = slip.SlipcodeId; works, i.e. it seems to know that if it is new and even with me setting that value it should still link the FKs properly? Note, it ll happens in a UOW.
It is only failing on the second one which makes me think there might be a problem with multiple FKs to the same table?
Any help is much appreciated...
Keep up all the good work!