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 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

I have the following code making a GET request on a URL: $('#searchButton').click(function() {
I have the following code, for which I get the error: Warning : mysqli_stmt::bind_result()
I have the following code, I'm trying to get a table with 4 columns
If I have the following Linq code: context.Table1s.InsertOnSubmit(t); context.Table1s.InsertOnSubmit(t2); context.Table1s.InsertOnSubmit(t3); context.SubmitChanges(); And I get
I have a unit test which contains the following line of code Site.objects.get(name=UnitTest).delete() and
currently i have jdbc code with the following basic stucture: get Connection (do the
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I'm trying to use opengl in C#. I have following code which fails with
I have the following code in a web.config file of the default IIS 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.