Issue with saving sub-type - PK field gets NULL value

Posts   
 
    
hotchill avatar
hotchill
User
Posts: 180
Joined: 22-Jan-2007
# Posted on: 23-Jul-2012 19:17:52   

Hi.

I am on LLBLGen v3.5 using 'LLBLGen Pro Runtime Framwork'. Db is sql server 2008 R2.

I have a SuperType Enquiry and a SubType AccessEnquiry. When saving a new AccessEnquiry object, I get

An exception was caught during the execution of an action query: Cannot insert the value NULL into column 'AccessEnquiryId', table 'ServiceManager.dbo.AccessEnquiry'; column does not allow nulls. INSERT fails.
The statement has been terminated.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.

AccessEnquiryId is the PK field of AccessEnquiry. It is not an identity field. I wrongly had it as identity field earlier, but changed that and refreshed model from db and generated code.

Enquiry has PK field EnquiryId. This is field is an Identity field.

Here is the FK I use for the inheritance relation:

ALTER TABLE [dbo].[AccessEnquiry]  WITH CHECK ADD  CONSTRAINT [FK_AccessEnquiry_Enquiry] FOREIGN KEY([AccessEnquiryId])
REFERENCES [dbo].[Enquiry] ([EnquiryId])
GO

ALTER TABLE [dbo].[AccessEnquiry] CHECK CONSTRAINT [FK_AccessEnquiry_Enquiry]
GO

Here is the trace when insert fails:

Step into: Stepping over non-user code 'SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.SaveEntity'
Method Enter: DataAccessAdapterBase.SaveEntity(4)
Active Entity Description: 
    Entity: Collabora.ServiceManager.Data.EntityClasses.AccessEnquiryEntity. ObjectID: e520a0cc-77f8-41fe-a849-234c0e21c875
    PrimaryKey field: EnquiryId. Type: System.Int64. Value: <undefined value>
    PrimaryKey field: EnquiryId. Type: System.Int64. Value: <undefined value>
Method Enter: ObjectGraphUtils.DetermineActionQueues(6)
Active Entity Description: 
    Entity: Collabora.ServiceManager.Data.EntityClasses.AccessEnquiryEntity. ObjectID: e520a0cc-77f8-41fe-a849-234c0e21c875
    PrimaryKey field: EnquiryId. Type: System.Int64. Value: <undefined value>
    PrimaryKey field: EnquiryId. Type: System.Int64. Value: <undefined value>
Step into: Stepping over non-user code 'SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.GetDependentRelatedEntityCoreInstances.MoveNext'
Step into: Stepping over non-user code 'SD.LLBLGen.Pro.ORMSupportClasses.ObjectGraphUtils.ProduceAdjacencyLists<SD.LLBLGen.Pro.ORMSupportClasses.IEntity2>'
Step into: Stepping over non-user code 'SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.GetDependingRelatedEntityCoreInstances.MoveNext'
Step into: Stepping over non-user code 'SD.LLBLGen.Pro.ORMSupportClasses.ObjectGraphUtils.ProduceAdjacencyLists<SD.LLBLGen.Pro.ORMSupportClasses.IEntity2>'
Step into: Stepping over non-user code 'SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.GetMemberEntityCollectionCoreInstances.MoveNext'
Step into: Stepping over non-user code 'SD.LLBLGen.Pro.ORMSupportClasses.ObjectGraphUtils.ProduceAdjacencyLists<SD.LLBLGen.Pro.ORMSupportClasses.IEntity2>'
Step into: Stepping over non-user code 'SD.LLBLGen.Pro.ORMSupportClasses.ObjectGraphUtils.ProduceTopologyOrderedList<SD.LLBLGen.Pro.ORMSupportClasses.IEntity2>'
Step into: Stepping over non-user code 'SD.LLBLGen.Pro.ORMSupportClasses.ObjectGraphUtils.DetermineActionQueues<SD.LLBLGen.Pro.ORMSupportClasses.IEntity2>'
Entity added to insert queue: 
    Entity: Collabora.ServiceManager.Data.EntityClasses.AccessEnquiryEntity. ObjectID: e520a0cc-77f8-41fe-a849-234c0e21c875
    PrimaryKey field: EnquiryId. Type: System.Int64. Value: <undefined value>
    PrimaryKey field: EnquiryId. Type: System.Int64. Value: <undefined value>
Entity added to insert queue: 
    Entity: Collabora.ServiceManager.Data.EntityClasses.EnquiryContactEntity. ObjectID: 81d03109-58c7-4512-bbe9-d4bfd8fc188b
    PrimaryKey field: EnquiryContactId. Type: System.Int64. Value: <undefined value>
Method Exit: ObjectGraphUtils.DetermineActionQueues(6)
Step into: Stepping over non-user code 'SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.SaveEntity'
Method Enter: DataAccessAdapterBase.StartTransaction
:   Transaction name: RecursiveSave. Isolation level: ReadCommitted.
Method Enter: DataAccessAdapterBase.OpenConnection
: New connection created.
: Connection physically opened.
Method Exit: DataAccessAdapterBase.OpenConnection
Method Exit: DataAccessAdapterBase.StartTransaction
Method Enter: DataAccessAdapterBase.PersistQueue
Persistence action info: Action: Insert. Queue length: 2
Current persisted entity info: 
    Entity: Collabora.ServiceManager.Data.EntityClasses.AccessEnquiryEntity. ObjectID: e520a0cc-77f8-41fe-a849-234c0e21c875
    PrimaryKey field: EnquiryId. Type: System.Int64. Value: <undefined value>
    PrimaryKey field: EnquiryId. Type: System.Int64. Value: <undefined value>
Method Enter: CreateInsertDQ
Method Enter: CreateSingleTargetInsertDQ
Generated Sql query: 
    Query: INSERT INTO [ServiceManager].[dbo].[Enquiry] ([Added], [AddedByUserId], [Description], [IsTempAttachmentHolder], [LastUpdated], [PrimaryContactUserId], [Status], [Subject], [Type]) VALUES (@p1, @p2, @p3, @p5, @p6, @p7, @p8, @p9, @p10) ;SELECT @p4=SCOPE_IDENTITY()
    Parameter: @p1 : DateTime. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 23.07.2012 16:55:54.
    Parameter: @p2 : Guid. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 3bc5fa09-d06a-4e16-8a37-23ca2431dcd7.
    Parameter: @p3 : String. Length: 4000. Precision: 0. Scale: 0. Direction: Input. Value: "Temp attachment placeholder".
    Parameter: @p4 : Int64. Length: 0. Precision: 19. Scale: 0. Direction: Output. Value: <undefined value>.
    Parameter: @p5 : Boolean. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: True.
    Parameter: @p6 : DateTime. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 23.07.2012 16:55:54.
    Parameter: @p7 : Guid. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 3bc5fa09-d06a-4e16-8a37-23ca2431dcd7.
    Parameter: @p8 : String. Length: 50. Precision: 0. Scale: 0. Direction: Input. Value: "Open".
    Parameter: @p9 : String. Length: 200. Precision: 0. Scale: 0. Direction: Input. Value: "Temp attachment placeholder".
    Parameter: @p10 : String. Length: 50. Precision: 0. Scale: 0. Direction: Input. Value: "AccessEnquiry".

Method Exit: CreateSingleTargetInsertDQ
Method Enter: CreateSingleTargetInsertDQ
Generated Sql query: 
    Query: INSERT INTO [ServiceManager].[dbo].[AccessEnquiry] DEFAULT VALUES ;SELECT @p11=SCOPE_IDENTITY()
    Parameter: @p11 : Int64. Length: 0. Precision: 19. Scale: 0. Direction: Output. Value: <undefined value>.

Method Exit: CreateSingleTargetInsertDQ
Method Exit: CreateInsertDQ
Method Enter: DataAccessAdapterBase.ExecuteActionQuery
Method Enter: DataAccessAdapterBase.OpenConnection
Method Exit: DataAccessAdapterBase.OpenConnection
Method Enter: Query.ReflectOutputValuesInRelatedFields
:   Syncing field EnquiryId with parameter @p4.
Method Exit: Query.ReflectOutputValuesInRelatedFields
Executed Sql Query: 
    Query: INSERT INTO [ServiceManager].[dbo].[Enquiry] ([Added], [AddedByUserId], [Description], [IsTempAttachmentHolder], [LastUpdated], [PrimaryContactUserId], [Status], [Subject], [Type]) VALUES (@p1, @p2, @p3, @p5, @p6, @p7, @p8, @p9, @p10) ;SELECT @p4=SCOPE_IDENTITY()
    Parameter: @p1 : DateTime. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 23.07.2012 16:55:54.
    Parameter: @p2 : Guid. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 3bc5fa09-d06a-4e16-8a37-23ca2431dcd7.
    Parameter: @p3 : String. Length: 4000. Precision: 0. Scale: 0. Direction: Input. Value: "Temp attachment placeholder".
    Parameter: @p4 : Int64. Length: 0. Precision: 19. Scale: 0. Direction: Output. Value: 100082.
    Parameter: @p5 : Boolean. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: True.
    Parameter: @p6 : DateTime. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 23.07.2012 16:55:54.
    Parameter: @p7 : Guid. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 3bc5fa09-d06a-4e16-8a37-23ca2431dcd7.
    Parameter: @p8 : String. Length: 50. Precision: 0. Scale: 0. Direction: Input. Value: "Open".
    Parameter: @p9 : String. Length: 200. Precision: 0. Scale: 0. Direction: Input. Value: "Temp attachment placeholder".
    Parameter: @p10 : String. Length: 50. Precision: 0. Scale: 0. Direction: Input. Value: "AccessEnquiry".


Method Exit: DataAccessAdapterBase.ExecuteActionQuery
Step into: Stepping over non-user code 'SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.SaveEntity'
Method Enter: DataAccessAdapterBase.Rollback
Method Enter: DataAccessAdapterBase.Reset
Method Exit: DataAccessAdapterBase.Reset
Method Exit: DataAccessAdapterBase.Rollback

Can anyone see what I am doing wrong?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 23-Jul-2012 19:48:17   

Does the entity have dirty fields to be inserted?

hotchill avatar
hotchill
User
Posts: 180
Joined: 22-Jan-2007
# Posted on: 23-Jul-2012 21:55:05   

I believe there is a bug in the designer.

The schema shown in the Catalog Explorer had the 'Is Identity' flag raised for the AccessEnquiryId PK field. I tried to refresh one more time from database, but the flag remained raised.

I then deleted the AccessEnquiry Entity from the project and also removed the AccessEnquiry table from the imported schema. I then did a refresh from database selecting to include the AccessEnquiry table. The AccessEnquiryId PK field now came over with 'Is Identity' correctly set to false.

I then generated the code and it worked.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-Jul-2012 07:40:52   

Are you using the latest build? If so, a detailed repro-case would be useful so we can reproduce over here as well. Can you give us a .llblgenproj, DB DDL and detailed steps? You can do that in a HelpDesk forum which is private.

David Elizondo | LLBLGen Support Team
hotchill avatar
hotchill
User
Posts: 180
Joined: 22-Jan-2007
# Posted on: 24-Jul-2012 10:47:27   

I am v3.5 Final (March 23rd, 2012).

I tried to scale down to just two tables. The identity flag was updated correctly when refreshing project from db.

I then checked that the same goes for my project. Changes to the Identity flag from db are now correctly reflected in the Designer Catalog Explorer.

So I am not able to reproduce, sorry.

Thanks for your help and a powerful tool guys.