INSERT statement missing params

Posts   
 
    
knez
User
Posts: 37
Joined: 01-Nov-2004
# Posted on: 30-Jun-2005 11:35:57   

Hi!

I encountered problem I don't know where to start solving. I have an entity object (IsNew = true) with all not null properties set, but when I try to save it, generated INSERT statement doesn't contain all params. What went wrong? Example:

Entity object (ToString() returns string with all field/values):
LeasingAgreementEntity:LeasingAgreementId=0;LeasorId=49;LeaseeId=1809;
DistributorId=1809;LeasingAgreementReferenceNumber=BG04310;LeasingAgreementSettlementDate=2.2.2005;
LeasingAgreementDuration=60;LeasingAgreementLastPaymentDate=1.2.2010;
LeasingAgreementTotalValue=148069,5600;LeasingAgreementDeliveryDate=1.1.2005;
LeasingAgreementDeliveryPlace=;LeaseeAuthority=False;LeasingAgreementOptionId=1;
LeasingAgreementComment=;LeasingAgreementSuperiorId=1716;LeasingAgreementRegistrationDate=1.1.0001
;LeasingAgreementInsertDate=1.1.0001;LeasingAgreementInsertUser=0;

Executed INSERT statement:
exec sp_executesql N'INSERT INTO [RegistarLizinga].[dbo].[LeasingAgreement] ([LeasorId],[LeaseeId],[DistributorId],[LeasingAgreementSuperiorId]) VALUES (@LeasorId,@LeaseeId,@DistributorId,@LeasingAgreementSuperiorId);SELECT @LeasingAgreementId=SCOPE_IDENTITY()', N'@LeasingAgreementId bigint output,@LeasorId bigint,@LeaseeId bigint,@DistributorId bigint,@LeasingAgreementSuperiorId bigint', @LeasingAgreementId = @P1 output, @LeasorId = 49, @LeaseeId = 1809, @DistributorId = 1809, @LeasingAgreementSuperiorId = 1716 

Thanks! Vladimir

knez
User
Posts: 37
Joined: 01-Nov-2004
# Posted on: 30-Jun-2005 16:41:02   

I solved the problem. I didn't realize that even the entity object IsNew is set to true, DQE generates INSERT params by checking each field IsChanged property. Client code created "new" objects by fetching old ones from database and setting PK value to NULL and IsNew to true.

Vladimir

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 01-Jul-2005 10:41:14   

yes, every field is checked if it's changed. That way you can insert NULL values by simply not setting a value on a new entity (which semantically means that field is thus not set and 'undefined', which means NULL in the db) simple_smile

Frans Bouma | Lead developer LLBLGen Pro