I have a Database with the tables Users and Uploads. The important columns are:
Users -> UserID
Uploads -> UploadID, UserID
The primary key in the relationship is Users -> UserID and the foreign key is Uploads -> UserID.
In LINQ to SQL, I do the following operations:
Retrieve files
var upload = new Upload();
upload.UserID = user.UserID;
upload.UploadID = XXX;
db.Uploads.InsertOnSubmit(upload)
db.SubmitChanges();
If I do that and rerun the application (and the db object is re-built, of course) - if do something like this:
foreach(var upload in user.Uploads)
I get all the uploads with that user's ID. (like added in the previous example)
The problem is, that my application, after adding an upload an submitting changes, doesn't update the user.Uploads collection. i.e - I don't get the newly added uploads.
The user object is stored in the Session object. At first, I though that the LINQ to SQL Framework doesn't update the reference of the object, therefore I should simply "reset" the user object from a new SQL request. I mean this:
Session["user"] = db.Users.Where(u => u.UserID == user.UserID).SingleOrDefault();
(Where user is the previous user)
But it didn't help.
Please note: After rerunning the application, user.Uploads does have the new upload!
Did anyone experience this type of problem, or is it normal behavior? I am a newbie to this framework. I would gladly take any advice.
Thank you!