in Education by
I'm using EF code first. By convention, I have added a foreign key and a reference to the foreign object (I believe this is needed). When I send a Get request to the API, it returns an IEnumerable. The problem is that each record returned also returns the complete object for the foreign key. I've tried Googling the answer and for questions here on SO. I tried commenting out the reference to the other object but that didn't work. public class Bill { // other properties public Guid PersonId { get; set; } // this is the foreign key public Person Person { get; set; } // this is the reference to the foreign object } This is what is returned when executing the Get request: [ { //other fields "personId": "c28e52b0-1e40-46c4-812b-a61be7a69d53", "person": { //the entire other person object is returned here } }, ] How do I solve this without establishing a DTO for every model? I'd like to hear if I'm using code first conventions improperly. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
ASP.NET core 2.2 doesn't have return type Json(Object) as 2.1 did. An ActionResult returning an anonymous type is one option, if you didn't want to use a DTO. public IActionResult Get() { return new OkObjectResult(new { PersonId = 99, OtherProperty = "more stuff" }); } Response body: { "personId": 99, "otherProperty": "more stuff" } Use ObjectResult if you need to return various status codes: return new ObjectResult(new { PersonId = 99, OtherProperty = "more stuff"}) {StatusCode = 200};

Related questions

0 votes
    I have an Azure SQL DB that initially had the following columns: user name password hash password salt This ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I've searched stackoverflow for a proper solution on generating a many-to-many relationship, using EF Core, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 13, 2022 in Education by JackTerrance
0 votes
    In the above DDL command the foreign key entries are got by using the keyword (a) References (b) ... Answers, Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    What is Database First Approach in MVC using Entity Framework?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
    For a weak entity set to be meaningful, it must be associated with another entity set, called the ( ... , Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    Which of the following is a web application API framework? (a) Dojo (b) YUI (c) GWT (d) jQuery ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
    I want to test my Entities that are built using Entity Framework. My concern is that using Entity Framework ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I try to create database from entity framework code first follow with this tutorial http://www.asp.net/mvc ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    In my unit test I am calling the following: every { connectivityManager.activeNetworkInfo } returns null but ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I have the following models: class Project(models.Model): name = models.CharField(max_length=300, unique= ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    I am using Laravel 5.7 version. I got the below error for users_activations table while run the command ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    I am using Laravel 5.7 version. I got the below error for users_activations table while run the command ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    I'm trying to add foreign key in my table exam: public function up() { Schema::create('exams', ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    Suggestions needed for creating better and efficient search indexes for models having foreign key and many-to-many ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    5. Which key defines a relationship between two tables? (a) Primary key (b) Foreign key (b) Secondary key (d) ... Full form of RDBMS is Select the correct answer from above options...
asked Dec 21, 2021 in Education by JackTerrance
...