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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:44:38+00:00 2026-05-13T17:44:38+00:00

I have generated few classes using to LINQ to SQL one of them being

  • 0

I have generated few classes using to LINQ to SQL

one of them being “Customer”

Now I want to create a Customer object that is disconnected.

i.e. I can create the object keep it in session and then attach it back only if I want to. Not automatically. Hence only if I attach it – it should affect my context’s SubmitChange() otherwise not.

Is this possible?

Also can I add this detached object to a collection of attached objects without affecting SubmitChanges() or on add will the detached object become attached again?

  • 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-13T17:44:38+00:00Added an answer on May 13, 2026 at 5:44 pm

    There’s no “Detach” method, but it is possible with serialization:

    Customer customerCopy;
    BinaryFormatter bf = new BinaryFormatter();
    using (MemoryStream ms = new MemoryStream())
    {
        bf.Serialize(ms, customer);
        ms.Position = 0;
        customerCopy = (Customer)bf.Deserialize(ms);
    }
    

    Be aware that it’s cumbersome to re-attach the object afterward. The Attach table method is finicky – you generally need a Version (timestamp type) column on the entity in order for it to work.

    Note – I just reread your question and it sounds almost as though you simply want to construct the object. If so, constructing a new Customer via new Customer() will not create an attached entity. It only becomes attached after you invoke the InsertOnSubmit or Attach method on the table.

    Also, you can freely add detached entities to a List<Customer> (or similar) containing attached entities – Linq to SQL does not care about this, an entity only becomes attached if it is dispensed by the DataContext itself or if you attach it using one of methods above.

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

Sidebar

Related Questions

I have a set of linq to sql classes and serialized them into JSON
I have few own APIs with around 2000 classes overall. Some of them use
We are using JAXB to generate Java classes and have encountered a few cases
I have few classes and functions in java code. one of the function is
I have a few dmp files (generated by different a user) I need to
I have generated a DAL layer with Subsonic2.2 for a .NET4.0 application, using c#
I have generated a pdf file with password protection by using the following code:
I have generated a collection of images. Some of them are blank as in
I have generated a C# SharePoint Sequential Workflow project using the very handy STSDEV
I have generated inputs with price values. Example: <input type=text value=59,00/> Now I should

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.