Default Object being modified because of LINQ Query

Posted by msarchet on Stack Overflow See other posts from Stack Overflow or by msarchet
Published on 2010-05-06T18:48:21Z Indexed on 2010/05/06 18:58 UTC
Read the original article Hit count: 400

Filed under:
|
|

I'm doing the following code to filter a list of objects before it gets sent off to be printed.

Dim printList As New List(Of dispillPatient)
        For Each pat As dispillPatient In patList
            If (From meds In pat.Medication Select meds Where meds.Print = True).Count > 0 Then
                Dim patAdd As New dispillPatient
                patAdd = pat
                patAdd.Medication = DirectCast((From meds In pat.Medication Select meds Where meds.Print = True).ToList, List(Of dispillMedication))
                printList.Add(patAdd)
            End If
        Next

What is happening is patList, which is my initial list, for every dispillPatient inside of it, that specific patients Medication object (which is another list), is being shorten to the list that is returned to the patAdd object.

I think this has something to do with both the way that .NET makes the copy of my pat object when I do patAdd = pat and the LINQ query that I'm using. Has anyone had a similar issue before and\or what can I do to keep my initial list from getting truncated.

Thanks

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about .NET