Need help with UnitOfWork

Posts   
 
    
dgau
User
Posts: 2
Joined: 16-Apr-2005
# Posted on: 30-Jun-2006 23:58:43   

I have two tables, the second of which contains a field that references the key of the first:

CREATE TABLE [dbo].[Name] ( [id] [uniqueidentifier] DEFAULT newid() NOT NULL PRIMARY KEY , [name] [varchar] (64) NOT NULL , [referenceId] [uniqueidentifier] NOT NULL, [createDate] [datetime] DEFAULT getDate() NOT NULL , [lastUpdateDate] [datetime] DEFAULT getDate() NOT NULL ) ON [PRIMARY] ; CREATE TABLE [dbo].[Pronunciation] ( [id] [uniqueidentifier] DEFAULT newid() NOT NULL PRIMARY KEY , [pronunciation] [varchar] (96) NOT NULL , [nameId] [uniqueidentifier] NOT NULL REFERENCES Name(id), [createDate] [datetime] DEFAULT getDate() NOT NULL, [lastUpdateDate] [datetime] DEFAULT getDate() NOT NULL ) ON [PRIMARY] ;

I need to delete an entry in Name and its associated Pronunciations in one transaction so I am trying the following: Guid aGuid = new Guid(aNameId); UnitOfWork deleteNameUOW = new UnitOfWork(); deleteNameUOW.AddDeleteMultiCall(new PronunciationCollection(), PredicateFactory.CompareValue(PronunciationFieldIndex.NameId, ComparisonOperator.Equal, aGuid)); deleteNameUOW.AddForDelete(new NameEntity(aGuid)); deleteNameUOW.Commit(new Transaction(IsolationLevel.Serializable, "DeleteName"), true);

The problem is I get a foreign key constraint error: DELETE statement conflicted with COLUMN REFERENCE constraint 'FK__Pronuncia__nameI__4A4E069C'. The conflict occurred in database 'vdialer', table 'Pronunciation', column 'nameId'.

It seems like it always tries to delete the NameEntity before deleting all the pronunciations. If I put the delete of the name entity into another transation it works fine. So how can I do this in one transaction?

I'm using 1.0.2005.1 Final llbl, runtime library 1.0.20051.60621, .net 1.1, vs.net 2003

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 01-Jul-2006 08:44:29   

Either use both DeleteMulti calls or don't use a unitofwork and just 1 transaction and use the same transaction object for both statements (deletemulti and delete). THe problem is that deletemulticalls are executed after the normal deletes in a UoW

Frans Bouma | Lead developer LLBLGen Pro