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 665141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:40:37+00:00 2026-05-13T23:40:37+00:00

Its a simple question, but I’m not aware of the answer and I couldn’t

  • 0

Its a simple question, but I’m not aware of the answer and I couldn’t get it to work.

Can I update only one entity on the entire DataContext? Or should I follow plain ADO.NET for this operation only?

Edit:

public MyObject GetMyObjectById(int selectedId)
    {
        DataContext db = _dbManager.GetContext();

        return db.MyObject.SingleOrDefault(p => p.Id == selectedId);
    }

I am getting an object with the above query…
I am querying then for an integer…on another table/object

 public int GetMyInteger()
    {
        DataContext db = _dbManager.GetContext();

        return db.MyAnotherObject.FirstOrDefault().MyInteger;
    }

Everything is fine for all my operations…but now i just want to update only the integer i got from the database…

 public void SetMyInteger(int updInteger)
    {
        DataContext db = new DataContext(ConnectionString);

        MyAnotherObject theEntity = db.MyAnotherObject.FirstOrDefault();
        atheEntity.MyInteger = updInteger;
        db.SubmitChanges(ConflictMode.ContinueOnConflict);
    }

The above method deleted MyObject i got from the first query!!! Of course if i use the static context DataContext tries to update MyObject and MyAnotherObject which seems the correct behaviour.

Edit:

I have changed the method getting the integer with a new datacontext as well and seems to working correctly, i have a strange thought on why called the delete method, because it was the method that was called, but again .. is working now…

Thank you all for your time.

  • 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-13T23:40:38+00:00Added an answer on May 13, 2026 at 11:40 pm

    Yes it’s possible. What have you tried? It should be as simple as this:

    using (var dc = new YourDataContext())
    {
        Person p = dc.Persons.Take(1).Single();
        p.FirstName = "Ahmad";
        dc.SubmitChanges();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think its a rather simple question but I couldn't really find an answer
Simple question, but one I can't find an answer to on the MSDN subscriber
I have read this question and the simple and clear answer but it's not
I think its quite a simple question but not sure. I have a class:
I have a quite simple question but the answer is not so easy. I
It may be a simple question, but i could't get the answer and needing
Simple question, but for some reason I couldn't find the exact answer on Google:
Seems like a super simple question but I can't find an answer. I'm grabbing
May be its a simple question but it's really driving me crazy. I just
I'm aware it's a quite simple question but I'm a newbie to C#, ASP.NET

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.