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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:38:30+00:00 2026-06-07T14:38:30+00:00

In my Web API controller, I return the results to a method call like

  • 0

In my Web API controller, I return the results to a method call like so:

// GET api/profile/5
public VCompleteProjectProfile GetBasicProjectProfile(int id)
{
    return _dbss.GetBasicProfile(id);
}

And here is the actual result:

{
    "$id":"1",
    "Id":1,
    "ProjectName":"Caribbean Challenge",
    "IsMrRcSelected":true,
    "IsMrdProject":true,
    "RegionName":"North America",
    "EntityKey":{
        "$id":"2",
        "EntitySetName":"VCompleteProjectProfile",
        "EntityContainerName":"MrdViewEntities",
        "EntityKeyValues":[
            {"Key":"Id","Type":"System.Int32","Value":"1"},
            {"Key":"ProjectName","Type":"System.String","Value":"Caribbean Challenge"},
            {"Key":"IsMrRcSelected","Type":"System.Boolean","Value":"True"}
        ]
    }
}

Is it possible to suppress the EntityKey? If so, how? This is MVC4.

Thanks
Eric

  • 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-07T14:38:33+00:00Added an answer on June 7, 2026 at 2:38 pm

    Create a DTO/POCO for your result instead of returning the actual entity object e.g.

    var entity = _dbss.GetBasicProfile(id);
    return new ProfileDto()
    {
        Id = entity.Id,
        ProjectName = entity.ProjectName,
        ....
    };
    

    You could even extend your entity type to include a function called ToDto which would do this for you e.g.

    public partial class ProfileEntity
    {
        public ProfileDto ToDto()
        {
            return new ProfileDto()
            {
                Id = this.Id,
                ProjectName = this.ProjectName,
                ....
            };
        }
    }
    
    ....
    
    var entity = _dbss.GetBasicProfile(id);
    return entity.ToDto();
    

    A general rule of thumb is only return data that is needed, don’t cut corners just because it’s convenient.

    Also, if you find yourself having to do this all over the place look at something like AutoMapper, will make your life a lot easier.

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

Sidebar

Related Questions

Let say I have two methods in MVC 4 Web API controller: public IQueryable<A>
The standard route for the MVC Web API is {controller}/{id}. However I'd like to
Using the ASP.NET Web-Api, I have the following POST setup in my controller. When
I am using MVC4's WEB API to expose a controller. Initially I created created
I'm experimenting with ASP.Net Web API, which, by convention, splits controller methods into a
I am building a Web API using MVC4 and some request return blocks of
I am calling a Web API through $.ajax() call. And I am getting the
New ASP.NET Web API HttpClient has been giving me some strange results. Here is
Consider an ASP.NET Web API service that redirects public class ThisController : ApiController {
I have a Web API controller action which has a parameter of type CommandMessage.

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.