Deleting rows that meet a criteria

Posts   
 
    
hplloyd
User
Posts: 191
Joined: 29-Oct-2004
# Posted on: 11-Jan-2005 13:16:36   

I want to creat a "Purge" method that deletes all rows from the database where the Deleted field that I have in my datatable is true.

What I dont want to do is load the collection first, I think I want to use adapter.DeleteEntityCollection but I cant see how to use this unluess I load the collection into memory first.

Is there a quick and easy way to delete the rows in a database table where one column is equal to a specified value?

Thanks in advance

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 11-Jan-2005 14:09:35   

You want to use adapter.DeleteEntitiesDirectly() I think simple_smile

Frans Bouma | Lead developer LLBLGen Pro
hplloyd
User
Posts: 191
Joined: 29-Oct-2004
# Posted on: 11-Jan-2005 14:43:12   

Thanks

I am having a bit of trouble getting it to work...

Please tell me what I am doing wrong


EntityCollection myCollection = new EntityCollection(new UserGroupMenuItemEntityFactory());
                        
IRelationPredicateBucket myFilter = new RelationPredicateBucket();
myFilter.PredicateExpression.Add(PredicateFactory.CompareValue(UserGroupMenuItemFieldIndex.Deleted, ComparisonOperator.Equal, false));

DataAccessAdapter LLBLAdapter = new DataAccessAdapter(this.ConnectionString,false,
CatalogNameUsage.ForceName,new ConfigSetting().GetConfigSetting("DBCatalog"));

LLBLAdapter.DeleteEntitiesDirectly(myCollection,myFilter);


Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 11-Jan-2005 16:14:15   

hplloyd wrote:

Thanks

I am having a bit of trouble getting it to work...

Please tell me what I am doing wrong


EntityCollection myCollection = new EntityCollection(new UserGroupMenuItemEntityFactory());
                        
IRelationPredicateBucket myFilter = new RelationPredicateBucket();
myFilter.PredicateExpression.Add(PredicateFactory.CompareValue(UserGroupMenuItemFieldIndex.Deleted, ComparisonOperator.Equal, false));

DataAccessAdapter LLBLAdapter = new DataAccessAdapter(this.ConnectionString,false,
CatalogNameUsage.ForceName,new ConfigSetting().GetConfigSetting("DBCatalog"));

LLBLAdapter.DeleteEntitiesDirectly(myCollection,myFilter);


That's not what you should do simple_smile You should do:


IRelationPredicateBucket myFilter = new RelationPredicateBucket();
myFilter.PredicateExpression.Add(PredicateFactory.CompareValue(UserGroupMenuItemFieldIndex.Deleted, ComparisonOperator.Equal, false));

DataAccessAdapter LLBLAdapter = new DataAccessAdapter(this.ConnectionString,false,
CatalogNameUsage.ForceName,new ConfigSetting().GetConfigSetting("DBCatalog"));
LLBLAdapter.DeleteEntitiesDirectly("UserGroupMenuItemEntity", myFilter);

Frans Bouma | Lead developer LLBLGen Pro
hplloyd
User
Posts: 191
Joined: 29-Oct-2004
# Posted on: 12-Jan-2005 09:54:21   

Aah I see thanks