New entity not inserted/saved

Posts   
 
    
oneness
User
Posts: 21
Joined: 10-Jan-2008
# Posted on: 11-Jan-2008 10:30:42   

Hi there

This is my first project with LLBLGen so please forgive me if I am missing something. It has taken me a while to get used to the paradigm shift but the general ease of use, clarity, stability and reliability of the generated code has made it a pleasure - thank you for the care that has obviously been taken in creating this tool.

My context details are as follows: LLBLGen v2.5 Final (November 5th 2007) Adapter, .NET2 SQLServer 2005

I have a table with the following structure;

CREATE TABLE [dbo].[tblDeptSettlement](
    [DeptSettlementID] [int] IDENTITY(1,1) NOT NULL,
    [DateAltered] [smalldatetime] NOT NULL CONSTRAINT [DF_tblDeptSettlement_DateAltered]  DEFAULT (getdate()),
    [Version_No] [timestamp] NOT NULL,
 CONSTRAINT [PK_DeptSettlement] PRIMARY KEY CLUSTERED 
(
    [DeptSettlementID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

If I instantiate a new DeptSettlement entity and attempt to save it, it is not inserted. If I explicitly set the DateAltered property in code before saving, then it is inserted. On further examination I noticed that in the first scenario, although the entity's IsNew flag is true, the IsDirty flag is still false. Therefore, if I don't set the DateAltered value in my code but I explicitly set DeptSettlement.IsDirty = true then it inserts the new record. Is this behaviour expected/by design? I would have thought that if you created a new entity and saved it, it would be inserted, regardless of whether you were explicitly/manually setting any properties on the entity. Is there a particular reason that IsNew = true does not automatically imply IsDirty = true?

Cheers

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Jan-2008 11:02:22   
oneness
User
Posts: 21
Joined: 10-Jan-2008
# Posted on: 11-Jan-2008 11:35:19   

Thank you for the prompt reply. I understand what was explained in the other post but I am still curious whether this applies to a table such as the one above that contains fields which have default values specified? Are these default values not "represented" in the generated code? Is that why they would still not set the entity.IsDirty = true?

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Jan-2008 11:46:16   

Default values isn't captured in the metadata retrieved from the database.

oneness
User
Posts: 21
Joined: 10-Jan-2008
# Posted on: 11-Jan-2008 13:30:35   

Thanks for clearing that up.