I have the following code:
Using dbContext As pbu_housingEntities = New pbu_housingEntities
' First, delete all current records associated with the specified semester.
Dim delete_old = (From p In dbContext.Residents _
Where p.semester = txtDestSemester.Text _
Where p.year = txtDestYear.Text _
Select p)
dbContext.Residents.DeleteObject(delete_old)
dbContext.SaveChanges()
End Using
But it doesn’t work. It throws an unable to cast object of type ‘System.Data.Objects.ObjectQuery’ error. Any thoughts?
All I’m trying to do is grab a list of rows with specified conditions and then delete all the rows returned.
In
delete_oldcould be more than 1 item.Add a
ToList()and iterate over each entry and call theDeleteObjectmethod for each enumerated item.