Strange Entity Save Error.

Posts   
 
    
Dusty
User
Posts: 24
Joined: 19-Feb-2008
# Posted on: 27-Aug-2008 19:36:19   

Version: 2.5 Final Runtime Library Version: 2.5.08.0122 Template: Self-Servicing .NET Version: 2.0 Database: SQL Server 2005

I am having a strange problem.

I have a Windows Forms application that is using LLBLGen. I have a particular form that is used to configure inventory parts called PartConfiguratorForm.

Based on the 'Part Type' there is the functionality to launch another instance of PartConfiguratorForm, configure a child part to be linked to the currently selected part, and return to the parent form.

The form creates an entity called 'PartEntity' that is saved at the end of the configuration process.

The strange thing is that the entity saves with no errors on the initial instance of the PartConfiguratorForm but an error gets thrown when trying to save the entity on a 'sub' instance of the form.

The error is:

An exception was caught during the execution of an action query: Cannot insert the value NULL into column 'PartNumber', table 'ACRO_Manufacturing.dbo.Part'; 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.

Stack Trace: at SD.LLBLGen.Pro.ORMSupportClasses.ActionQuery.Execute() at SD.LLBLGen.Pro.ORMSupportClasses.BatchActionQuery.Execute() at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.ExecuteActionQuery(IActionQuery queryToExecute, ITransaction containingTransaction) at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.AddNew(IEntityFields fields, ITransaction containingTransaction) at ABS.BusinessObjects.EntityClasses.PartEntity.InsertEntity() in C:\Documents and Settings\dlau.CSD\My Documents\LLBLGen Pro Projects\ACRO Manufacturing\EntityClasses\PartEntity.cs:line 6655 at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.CallInsertEntity() at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PersistQueue(List`1 queueToPersist, Boolean insertActions, ITransaction transactionToUse, Int32& totalAmountSaved) at SD.LLBLGen.Pro.ORMSupportClasses.UnitOfWork.Commit(ITransaction transactionToUse, Boolean autoCommit) at ABS.UI.PartConfigurator.PartConfiguratorForm.SaveEntity() in C:\ACRO\ABS.UI.PartConfigurator\ABS.UI.PartConfigurator\PartConfiguratorForm.cs:line 475

The 'QueryExecuted' is: INSERT INTO [ACRO_Manufacturing].[dbo].[Part] ([Description], [PartType], [PartClass], [PartGroup], [SalesUnitPrice], [InventoryUM], [PurchasingUM], [PurchasingFactor], [Notes]) VALUES (@Description, @PartType, @PartClass, @PartGroup, @SalesUnitPrice, @InventoryUm, @PurchasingUm, @PurchasingFactor, @Notes) Parameter: @Description : String. Length: 50. Precision: 0. Scale: 0. Direction: Input. Value: "MY COMPONENT A". Parameter: @PartType : String. Length: 1. Precision: 0. Scale: 0. Direction: Input. Value: "P". Parameter: @PartClass : String. Length: 10. Precision: 0. Scale: 0. Direction: Input. Value: "ab". Parameter: @PartGroup : String. Length: 10. Precision: 0. Scale: 0. Direction: Input. Value: "abc". Parameter: @SalesUnitPrice : Decimal. Length: 0. Precision: 18. Scale: 4. Direction: Input. Value: 1. Parameter: @InventoryUm : String. Length: 10. Precision: 0. Scale: 0. Direction: Input. Value: "EA ". Parameter: @PurchasingUm : String. Length: 10. Precision: 0. Scale: 0. Direction: Input. Value: "EA ". Parameter: @PurchasingFactor : Decimal. Length: 0. Precision: 18. Scale: 5. Direction: Input. Value: 1. Parameter: @Notes : AnsiString. Length: 2147483647. Precision: 0. Scale: 0. Direction: Input. Value: "PART NOTES. ".

It is missing the 'PartNumber' column in the insert statement. The 'PartNumber' field does have a value of 'MY_COMP_A' right before running this code:

unitOfWork.AddForSave(partEntity, true);
unitOfWork.Commit(transaction, true);

Any idea why this could be happening? I am very confused.confused

Please help!

Dusty
User
Posts: 24
Joined: 19-Feb-2008
# Posted on: 27-Aug-2008 22:57:27   

I have some more information.

I originally thought that the error was being thrown only by a child instance of itself. However, the error occurs when the form is launched from any other form.

I am not sure what this means but I have identified and can reproduce the behavior.

Any thoughts?

DvK
User
Posts: 318
Joined: 22-Mar-2006
# Posted on: 27-Aug-2008 23:18:34   

Hi,

Can't you check if the field PartNumber has been really set (IsChanged property = true) ? So the PartEntity.Fields("PartNumber").IsChanged...

If not, the constructed INSERT statement will not contain this vital part for inserting a Part entity as it's a required field. Question then probably is : why does this field not have a proper value and others do ?

Regards, Danny

Dusty
User
Posts: 24
Joined: 19-Feb-2008
# Posted on: 27-Aug-2008 23:46:39   

Can't you check if the field PartNumber has been really set (IsChanged property = true) ? So the PartEntity.Fields("PartNumber").IsChanged...

You were right. I was creating the PartEntity using:

this._PartEntity = new PartEntity(partNumber);

The 'IsNew' property on the entity was 'true' and the 'PartNumber' field was set but the 'IsChanged' property on the field was 'false'.

I will have to use:

this._PartEntity = new PartEntity();
this._PartEntity.PartNumber = partNumber;

The reason for the initial inconsistency in behavior was due to differences in the forms constructors. The form accepted a part number string from its calling forms. The form ran fine when the default constructor was called.

That was frustrating. I am better now. Thank you very much!simple_smile