Hi, I have 2 simple LINQ codes written in VB NET below. Which are to select record from database table.
From the below 2 statements, they are almost identical, just the second query has one more condition in WHERE clause.
Dim queryOne = (From queryOneIn DatabaseContext.TableA
Where queryOne.SC = 123).ToList()(0)
queryOne.RQ = 100
Dim queryTwo = (From queryTwo In DatabaseContext.TableA
Where queryTwo.SC = 123 AndAlso queryTwo.RQ = 200).ToList()(0)
I was trying to get identical records from queryOne and queryTwo respectively, this is due to I want to insert a new record(the one "queryOne.RQ = 100") and then delete the old record(from queryTwo).
But when I debug the codes, I found that whenever the "queryOne.RQ = 100" is executed, the record fetched from "queryTwo" would be updated to 100 as well for its RQ column, thus resulting in I cannot delete the correct old record, which the RQ suppose to be 200. I was expecting a new line of record is inserted whenever AddObject() is invoked and not update directly.
I am not sure about this LINQ behavior whereas I was querying from 2 different codes by fetching the records into queryOne and queryTwo respectively, I was expecting the queryTwo would contains old record. But I am not sure why.
Any help would be appreciated.
What I have tried:
1. Search online for explanation but clueless on the keyword that I should use.