question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Include function not working with pgsql and .net core 2.1

See original GitHub issue

I try to add countries in my address object like this

public IActionResult  AllAddress()
{
    var AllAddresses = _context.Addresses.Include(a=>a.Country);
    var result = new
    {
        Addresses = AllAddresses
    };

   return Ok(result);
}

but it just loop and and give me

http://localhost:9807/api/Addresses/all net::ERR_CONNECTION_RESET 200 (OK)

kindly note if I remove include function and return only _context.Addresses it working fine without any issue ,also I check the database and I am sure every foreign key in address has it’s primary key in country , kindly help

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
austindrenskicommented, Nov 20, 2018

You should adjust your JSON serialization settings to ignore circular references, like so:



services.AddMvc()
        .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
        .AddJsonOptions(x =>
        {
            // or ReferenceLoopHandling.Ignore
            x.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize; 
            x.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.None;
        })

I’m going to close this issue now, as this is not related to EF Core. Please feel free to continue posting if you have additional questions or issues related to EF Core or the Npgsql provider.

2reactions
austindrenskicommented, Nov 20, 2018

@alrazyreturn wrote:

after I install the below package

Install-Package Npgsql.EntityFrameworkCore.PostgreSQL.Design
Install-Package Microsoft.EntityFrameworkCore.Tools
Install-Package Npgsql.EntityFrameworkCore.PostgreSQL -Version 2.1.2
Install-Package Microsoft.EntityFrameworkCore.Proxies -Version 2.1.4

You do not need to add Npgsql.EntityFrameworkCore.PostgreSQL.Design. That package is no longer maintained.

@alrazyreturn wrote:

Can you please reproduce your issue with a quick and simple console application, instead of using ASP.NET? This will allow us to isolate and understand things better.

could you please see this project it’s so simple I just create new core vue project and add to it my database using this command https://github.com/alrazyreturn/core_project

That project is far too involved for us to evaluate. As @roji wrote, we would need a minimal reproduction of this issue in the form of a console application that does not use ASP.NET Core.

Before going any further, try the following and please report back:

public IActionResult  AllAddress()
{
    var AllAddresses = _context.Addresses.Include(a=>a.Country);
    var result = new
    {
        Addresses = AllAddresses.ToList() // enumerate here in-scope
    };

   return Ok(result);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Npgsql.EntityFrameworkCore.PostgreSQL Error when ...
I am using EF Core and Npgsql.EntityFrameworkCore.PostgreSQL inside Azure functions to fetch data from a Postgres Database.
Read more >
Postgres Function not working while upgrading .NET Core
Earlier, the same code was working perfectly fine. We are using function instead of stored procedure. DbTransaction transaction = connection.
Read more >
Adding EF Core and PostgreSQL to an ASP. ...
In this post I describe how to add PostgreSQL and EF Core to your app, how to build a model, and run migrations...
Read more >
ASP.NET Core with PostgreSQL and Entity Framework Core
This article shows how to use PostgreSQL with ASP.NET Core 3.1 using Entity Framework Core.
Read more >
Docker: Adding PostgreSQL to .Net Core - Part 2
NET Core is not expecting to work with PostgreSQL – this is the first issue we're going to fix. Adding PostgreSQL to .NET...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found