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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:53:31+00:00 2026-05-11T06:53:31+00:00

I have a linq object that I’d like to retire when certain aspects are

  • 0

I have a linq object that I’d like to ‘retire’ when certain aspects are changed and the Save() method is called. The database does this by having a Terminated column which when set causes the object to be ignored on subsequent queries. I’d like to do this transparently so for example:

DataContext db = new DataContext(); Foo bar = (from a in db.table            where a.pk == somevalue            select a).Single();  bar.Price += 2; Console.WriteLine(bar.pk); bar.Save(); Console.WriteLine(bar.pk); 

The second WriteLine() should be a different key than the first because in the process of saving I’ve created a duplicate object and replaced bar with it. Essentially inside the save method I want to set this = newObj;. Is what I want possible or am I going about this the wrong way?

  • 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. 2026-05-11T06:53:32+00:00Added an answer on May 11, 2026 at 6:53 am

    You can change references (or more precisely the variables that hold them) if they are passed by reference:

    class Foo {   ...   public static void Save(ref Foo obj)   {     var newObj = obj._save() //your implementation     obj = newObj;   } } 

    There is no other way to change references. The reason is, that objects don’t know where they are referenced. The Foo object doesn’t know about any references to it.

    If you want the exact behaviour you outlined in your code, the only way to achieve this, is to change the contents of your Foo instance, i.e., overwrite each and every field with the updated values.

    Hope this helps.

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

Sidebar

Related Questions

I'm using linq to pull back an object (i.e. customer) that might have a
I have LINQ statement that looks like this: return ( from c in customers
I have a linq query and I am trying to put that in to
I have a LINQ-to-SQL DataContext that represents a parent-child relationship of Products to Prices.
I have two LINQ objects which have exactly the same columns and I would
I have a Linq to objects statement var confirm = from l in lines.Lines
I'm working with LINQ to objects and have a function where in some cases
I'm trying to do my linq 2 sql objects manually, so I have the
What I have: LINQ to SQL auto generated class, which corresponds to the shape
I have a LINQ to SQL generated class with a readonly property: <Column(Name:=totalLogins, Storage:=_TotalLogins,

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.