Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8194139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:43:10+00:00 2026-06-07T04:43:10+00:00

I have a Database with the tables Users and Uploads . The important columns

  • 0

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!

P.S I have a DB.Uploads.Count() line in another method, and it does increase after the addition of the upload.

Edit: Some things I have tried:

  1. The first method in my code (initialization) is db = new new DBDataContext();.
    I’ve adding db.Dispose; db = new DBDataContext(); after db.SubmitChanges(); in my first method, just to see if it does anything. It didn’t.

  2. As a quick fix, I did user.Uploads.Add(upload);. It does add the appropriate object to user.Uploads which is then used in the foreach loop. Well, duh. But I am still waiting for some explanation about this behavior. Thank you!
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:43:12+00:00Added an answer on June 7, 2026 at 4:43 am

    Storing the User object in the Session causes it to be disconnected from the data context on subsequent requests. Thus, any changes made to the database (for the user entity or any of its child entities) will not be reflected in the object instance.

    To deal this this, you have several options. As you have done, you could simply update the Session-stored object instance yourself any time you make changes. You could also reconnect the entity stored in the Session before making any database changes (which in itself can have issues). You could also refresh the session object instance any time you change the data. And finally, you could not store the object in the session at all, and just retrieve it from the database any time you need it.

    You mention that you tried refreshing the stored session object and it didn’t help. I’m assuming you did this after calling SubmitChanges(), correct? This should have worked. Could you post the two methods in question (ie. the full method inserting the new upload and the method containing the foreach loop) and how they interact, please?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my database I have three tables: Users: UserID (Auto Numbering), UserName, UserPassword and
I have three database tables: users emails invitations Emails are linked to users by
I have an existing database with users and administrators in different tables. I am
I have a database with three tables: user_table country_table city_table I want to write
So I have a database table with the Facebook page ID's of my users.
So I have a mySQL database with a 'users' table which includes a username,
I have an Android application that uses the Android database to create tables and
I have two tables in my database: user and media_contact . The media_contact table
Imagine we have two tables in the database, user (FK id_role) and role (PK
My database have got 4 table : users id username images id user_id image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.