LINQ Object Persistance
Using the following code here
Sub FooSub Dim db As New FooDataContext Dim u = From p In db.FooTable Where p.FooColumn = FooData Select p Do Stuff End Sub
Do I have to manually create a class to map the data from my FooTable if I want it to persist in the application? If I declare u as a class-wide variable, then once SubFoo ends, I can no longer access the data in u
u will only be
IQueryable<typeof(p)>. The database won't even be hit until you try to iterate over that collection.
If you want some objects to work with after the DataContext connection has closed, you'll want to call
u.ToList before you close the connection to get a list of the results.
From there, you can change the objects themselves as you like. If you want changes to persist back to the database, call