Problem while removing an item from list

Problem while removing an item from list

Old forum URL: forums.lhotka.net/forums/t/12341.aspx


simisreedharan posted on Thursday, January 30, 2014

I need to remove an item from a  list which derives from BusinessListBase. When i use remove method to remove that item from the list, actually it gets moved to the DeletedList. But the actual problem is in the deletedlist, each item lost its RecordUpdateLoginId. why is it so? I need this propertys value so that i could update it in the table. Please see commented line "this.DeletedList"

public void Remove(string categoryName, string runby)
{

Category newCategory = Category.GetCategory(categoryName);
newCategory.RecordUpdateLoginId = runby;
Remove(newCategory);

//this.DeletedList

}

cfarren replied on Thursday, January 30, 2014

Why are you updating the record on a delete? Shouldn't you be deleting it?

simisreedharan replied on Thursday, January 30, 2014

we are not physically deleting the record.

 

cfarren replied on Thursday, January 30, 2014

The DeletedList is processed via the DataPortal_Delete/DeleteSelf method when the list object is saved. Perhaps you could update the record directly in the database via a stored proc from within the DataPortal_Delete method to set the RecordUpdateLoginId to whatever value you want.

simisreedharan replied on Friday, January 31, 2014

Actually my item is getting removed from the list properly using the sp. But the problem is who deleted, that information is not getting passed through the stored procedure to the db. RecordUpdateLoginId is something that comes from the application side and gets stored on the db.

JonnyBee replied on Friday, January 31, 2014

You get a new object and does NOT add it to the list, and then you Remove the item which is not yet added?

How do you exepect this to work?

If you also override the equality operator - then there is a possibility that the Remove will lookup the existing item in the list and Remove that item!!!!

I would assume that the item is already in the list and so you must

From MSDN documentation:
http://msdn.microsoft.com/en-us/library/ms132413(v=vs.110).aspx 

Collection<T>.Remove Method
Removes the first occurrence of a specific object from the Collection<T>.
This method determines equality using the default equality comparer EqualityComparer<T>.Default for T, the type of values in the list.

simisreedharan replied on Friday, January 31, 2014

Hi Jonny,

I am not getting a new object. Actually Category.GetCategory is getting the existing one from database. Then i am setting additional properties like RecordUpdateLoginId and then trying to remove this object from the list. But still when i check the DeletedList, the removed item is there in the deletedlist but RecordUpdateLoginId is still empty. Thats my problem.

public void Remove(string categoryName, string runby)
{

Category newCategory = Category.GetCategory(categoryName);
newCategory.RecordUpdateLoginId = runby;
Remove(newCategory);

//this.DeletedList

}

Thanks

Simi

simisreedharan replied on Friday, January 31, 2014

yes jonny. You are right. I changed the code as follows and it worked.

 this[categoryName].RecordUpdateLoginId = runby;
 Remove(this[categoryName]);

Thanks

Simi

Copyright (c) Marimer LLC