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

  • SEARCH
  • Home
  • 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 1074311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:06:25+00:00 2026-05-16T21:06:25+00:00

So I have the following code: // Get the current user _currentUser = WindowsIdentity.GetCurrent();

  • 0

So I have the following code:

// Get the current user
_currentUser = WindowsIdentity.GetCurrent();

// Get the list of address for the current user
_dataMap = new DataMapDataContext();
_addresses = _dataMap.Addresses
         .Where(address => address.InsertUserName == _currentUser.Name).ToList();

….

_addresses.Add(form.Item);
_dataMap.SubmitChanges();

When I call SubmitChanges nothing is saved in the database. Why is that? Am I missing the point? I thought with linq to sql you could just add items to your query results and then call SubmitChanges and it will work…. Clearly I am missing something.

Does it now work if you use “ToList”? If not then how do you insert stuff into the collection? (I don’t think Add is part of IQueryable.)

  • 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-05-16T21:06:26+00:00Added an answer on May 16, 2026 at 9:06 pm

    Dont use _addresses.Add

    You can’t add directly to an IQueryable, you need to add it to the entity set.

    Try this:

        _dataMap.Addresses.InsertOnSubmit(form.Item);
        _dataMap.SubmitChanges();
    

    Of course, i can’t see what form.Item is, but be aware it needs to be of the same Entity type as the _dataMap.Addresses entity set.

    It makes no difference if you use .ToList().

    With LINQ-SQL (unless you’re using some sort of POCO mapping), you can’t add items to a collection/query, you need to add the item directly into the Entity Set for the specified Data Context.

    You can call .InsertOnSubmit as many times as you like, and .SubmitChanges will push all those INSERT’s to the DB for you.

    More info on InsertOnSubmit here.

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

Sidebar

Related Questions

In C programming how do you get the current user and the current working
I have the following code section, designed to count how many Excel processes are
I have a mapview where I want to track the user's current location. GPS
We have an archive site that is an exact copy of the live site,
Microsoft Office documents, im my case: PowerPoint presentations, can have restricted permissions. How can
I've noticed if you change the security settings for a particular directory, you can
I'm currently about two-and-a-half weeks in to my first ASP.Net MVC application, and so
I’ve inherited a rather convoluted project. The original designer created a cookie that appears
I followed the official Authlogic tutorial but something came up. I successfully created a
At the moment, I am creating some kind of admin panel/backend for my site.

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.