Removing an entity from a collection using its PK

Posts   
 
    
Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 03-Jan-2008 18:10:42   

Hi, (LLBL 2.5/Adapter/SQL Srv 2.5/VB 2005/DevEx)

I can delete a row from a grid with reference to an index using:

CType(StaffBindingSource.DataSource(), EntityCollection(Of StaffEntity)).RemoveAt(idx)

but I need to specify its PK, as in

CType(StaffBindingSource.DataSource(), EntityCollection(Of StaffEntity)).Remove(rowPK)

but what is the syntax for avoiding this 'rowPK' error:

Value of type 'String' cannot be converted to 'MIS.DAL.EntityClasses.StaffEntity'

Pls note: I'm not trying to delete from the DB, just the collection that forms the datasource for the grid.

Thanks

gabrielk avatar
gabrielk
User
Posts: 231
Joined: 01-Feb-2005
# Posted on: 03-Jan-2008 19:16:57   

Hi,

Maybe you could first try to retrieve it's index in the DataSource (not per definition the same as the row number I thought) and then use it in RemoveAt().

Or use an EntityView, filter on the PrimaryKey to fetch the entity and use it in Remove()

Cheers, Gab

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

Create an entity using the PK then use the collection.Remove() method passing that entity. Also you can use the collection.FindMatches() to return the index of the matched PK predicate, and then you can use the index to remove the entity from the collection.

Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 04-Jan-2008 13:21:45   

Thanks guys. Happy new year simple_smile