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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:32:52+00:00 2026-06-13T03:32:52+00:00

I am using EF5 code-first approach and I am just wondering should I detach

  • 0

I am using EF5 code-first approach and I am just wondering should I detach entity from EF context when exposed it through the Web API?

Let’s say I have API action method

[HttpGet]
public HttpResponseMessage Get(int id)
{
    var user = _userRepository.GetById(id);

    if (user != null)
    {
        // detach here???
        _userRepository.Detach(user);

        return Request.CreateResponse(HttpStatusCode.Found, user);
    }

    return Request.CreateErrorResponse(HttpStatusCode.NotFound, string.Format("No user with id={0} is found", id));
}

Actually what are the best practices for that? Should I create the projection of the entity and then exposed it?

  • 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-06-13T03:32:54+00:00Added an answer on June 13, 2026 at 3:32 am

    I don’t believe Detach is necessary, it will automatically be detached when you ever get it back.

    But considering that you only use it in a Request/Response environment, then it is sensible to load it with the NoTracking option in the first place. Eliminate overhead for functionality you will never use.

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

Sidebar

Related Questions

I'm using Code First with EF 5. Currently I have SPs that return just
I'm using EF5 code first in a simple test application at the moment to
I'm using Visual Studio 2012 for an MVC web app using code first method
I just got on board with EF 5 and am using their code-first migrations
I am using EF5 Code-first and therefore I have a DbContext with a Database
I started a project using Entity Framework 4.3 Code First with manual migrations and
I'm using EF5 Code First and I'm trying to store an IPAddress object. If
I am making an MVC4 web application using Entity Framework 5 (Database-first with generated
I am using MySQL with dotConnector from Devart. I'm trying to use the code-first
I'm currently writing a billing application using EF 5 Code First, and I'm running

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.