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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:00:26+00:00 2026-06-05T20:00:26+00:00

I am creating a ASP.Net Web API to expose an existing database for use

  • 0

I am creating a ASP.Net Web API to expose an existing database for use with handheld devices. I am also relatively new at Web API, EF, and everything else I’m trying to use on this project 🙂

I want the resulting data transfer to be as lightweight as possible but when the api returns an object, the serialized JSON has ‘EntityKey’ fields for itself and the rows from other tables that the object has a relationship with.

I’m now trying to use the ADO.NET DbContext Template Generator for the model code generation. This gets rid of the EntityKey fields but I still have the relationships showing up in the JSON.

All I want are the fields from the object to be serialized and to be able to deserialize JSON into these objects for inserts and updates. Is there a built-in way to do this?

What’s my best bet?

  • 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-05T20:00:28+00:00Added an answer on June 5, 2026 at 8:00 pm

    in your return value “select” a new type

    return ienumfromedmx.Select(o=> new { id = id, value = value, name = name});
    

    where these are the values that you want to return

    if you post some example code it might be easier to give you a more relevant code example

    using your book

    public Book GetBook(int id) { return books.SingleOrDefault(b => b.Id == id);}
    

    change to

    public dynamic GetBook(int id){
    return books.SingleOrDefault(b=>b.id == id).Select(new { id = id, Title  = Title, price = Price});
    }
    

    OR

    public object GetBook(int id){
    return books.SingleOrDefault(b=>b.id == id).Select(new { id = id, Title  = Title, price = Price});
    }
    

    OR (for reference sake – I’d use dynamic or object for the api rather than a JsonResult)

    public JsonResult GetBook(int id){
    return Json(books.SingleOrDefault(b=>b.id == id).Select(new { id = id, Title  = Title, price = Price}));
    }
    

    note if you’re using

    public JsonResult GetBook(int id){
    return Json(books.SingleOrDefault(b=>b.id == id).Select(new { id = id, Title  = Title, price = Price}));
    }
    

    and if you’re using httpget as opposed to post, then you’d need to use

    public JsonResult GetBook(int id){
    return Json(books.SingleOrDefault(b=>b.id == id).Select(new { id = id, Title  = Title, price = Price},JsonRequestBehavior.AllowGet);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're creating a new consumer/public-facing ASP.Net web app. There are two concerns: --Use cookie
I'm creating a web API based on the new ASP.NET Web API. I'm trying
Microsoft is encouraging developers to use asp.net web api for creating Restful services. I
I'm creating REST service using ASP.NET Web API. How can I return 401 status
I am creating a web api using asp.net mvc4 and the response output is
I am thinking about creating my new asp.net mvc web application compatible with native
After creating a new ASP.NET Web Service I want it only to support HTTP-POST
I'm creating an api using Asp.net web api. I have controller BookController with two
I'm just wondering, if you are creating a new ASP.NET web forms app in
Yesterday I began learning WCF by porting an existing ASP.NET Web Service. Creating the

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.