child collection items byref or byval

child collection items byref or byval

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


jhw posted on Thursday, March 29, 2007

I just finished a post about upgrading to csla 2.x so maybe that will solve my problem. Currently I am using 1.x

When I edit an item in a child business collection, I only get a byval copy of the item. I change it and then have to delete the original and put the new item into the collection. Now when I save, I have delete the original in the db, and put in a new one. This can be a real headache if I have db constraints due to foriegn keys pointing to the child collection objects.

Am I doing this all wrong or is there a way to directly change the child object in the child collection instead of replacing it and so then I only have to do an update in the db.

Thanks

Brian Criswell replied on Thursday, March 29, 2007

I think you might be thinking of VB.NET in VB6 terms.  There are two types of objects in .NET: value types and reference types.  Value types are ints, bools, enums and the like.  Reference types are full blown classes, such as CSLA objects.  When reference types are passed by value, the reference to the object is what is copied, not the object itself.  So just modify the item in your collection and save the collection.

jhw replied on Thursday, March 29, 2007

Yes, I just worked through the collection to get the index of the item I want to modify and set that item point to the new modified item.

Thanks

JCannelos replied on Monday, April 02, 2007

Brian,

Sorry to jump in here off topic but I couldn't find a way to email you directly. I need to implement the whole Grandchild collection scheme you guys were posting about and was wondering if I could please have a copy of the SafeDataRowReader class (C#). It would be a big help. Is it posted online somewhere?

Thanx!

J'son

Brian Criswell replied on Monday, April 02, 2007

http://forums.lhotka.net/forums/post/3541.aspx
Someone posted that they may have found a bug.  Do a search of the forums about a week or two ago.

If you need to reach someone directly, click on the user's name and then click on the private message link.

Copyright (c) Marimer LLC