DeleteEntity and ConstructFilterForUC...

Posts   
 
    
orenpeled
User
Posts: 53
Joined: 25-Jul-2005
# Posted on: 25-May-2006 09:33:35   

Hi

This is my code:

MyEntity myEntity = new MyEntity(); myEntity.UniqueField = "UniqueText"; daa.DeleteEntity(myEntity, myEntity.ConstructFilterForUCUniqueField());

and it doesn't work. Why?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 25-May-2006 10:25:15   

'doesn't work' is too vague. Please explain what exactly doesn't work: do you get an exception, you don't see a query generated? is the query wrong? Is there no delete taking place? Please enable DQE tracing (see manual: troubleshooting and debugging) to see which queries are executing

Frans Bouma | Lead developer LLBLGen Pro
orenpeled
User
Posts: 53
Joined: 25-Jul-2005
# Posted on: 26-May-2006 14:31:13   

OK, I can see that the filter-predicate is well-constructed, but the DeleteEntity method returns 'false'. However, when initialize the PK field of the entity it works just fine (but then whats the point...)

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 26-May-2006 15:07:31   

OK, I can see that the filter-predicate is well-constructed, but the DeleteEntity method returns 'false'.

Would you please try to run the generated SQL query directly against the database and see what the result is?

T0M
User
Posts: 7
Joined: 09-Nov-2009
# Posted on: 11-Jun-2010 15:38:56   

Since the author of this thread never elaborated, I'll make a reply here instead of creating a new topic:

I'm also asking myself what the point of the UC would be if the primary key has to be set.

Given the following Entity of which the primary key is not set:


            SessionEntity sessionEntity = new SessionEntity()
            {
                UserId = 355, // needed for UC
                AdminUserId = 0, // needed for UC
            };

Executing the code:


new DataAccessAdapter().DeleteEntity(session, session.ConstructFilterForUCUserIdAdminUserId()

The SQL that rolls out is the following:


DELETE FROM [Session] 
WHERE ( ( [Session].[SessionId] IS NULL)
AND ( [Session].[UserId] = @UserId1 AND [Session].AdminUserId] = @AdminUserId2))',N'@UserId1 int,@AdminUserId2 int',@UserId1=355,@AdminUserId2=0

Shouldn't the PK (SessionId) be left out in the WHERE clause of this SQL statement when a unique constraint is specified?

EDIT: Reading the documentation more carefully (deleteRestriction: Predicate expression, meant for concurrency checks in a delete query), I'm probably asking something that was well thought of beforehand.

The only option I see is first fetching the entity via the unique constraint and deleting it directly afterwards.

Excuse me in advance wink

psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 11-Jun-2010 17:37:26   

Using DeleteEntity on the DataAccessAdapter is for deleting entities already in memory (which behind the scenes uses the PK).

I've never used a UC filter for anything outside of fetching entities. However, take a look at DataAccessAdapter.DeleteEntitiesDirectly if you want to delete an entity based on a UC filter (or any filter).