c# – Connections to PostgreSql linq2db are not closed

Question:

Hello everyone. I ran into a problem when accessing postgresql – when loading data from another table, the connection does not close, even if I wrap dbContext in using, without loading data from another table, connections are closed correctly. I am using linq2db.

Here is the actual action that is called:

[HttpGet]
    public PageModel<Client> GetAllClientInformation(WebApiEntityPageCondition<Client> condition)
    {
        using (var db = new HybridCrmEssence(GlobalConfig.Database.PostgreCrm))
        {
            var d = from cli in db.Clients.LoadWith(p => p.Contacts)
                    select cli;

            return new PageModel<Client>()
            {

                Items = d.ToArray()
            };
        }
    }

Base context:

public class HybridCrmEssence : DataConnection
{
    public HybridCrmEssence(string connectionString) : base(new PostgreSQLDataProvider(), connectionString)
    {

    }

    public ITable<Client> Clients { get { return GetTable<Client>(); } }

    public ITable<Contact> Contacts { get { return GetTable<Contact>(); } } 
}

And the models themselves:

[Table("Clients")]
public class Client : DbModel
{


    [Association(ThisKey = "Id", OtherKey = "ClientId")]
    public List<Contact> Contacts { get; set; } 

}
[Table("Contacts")]
public class Contact : DbModel
{

    [Column]
    public int ClientId { get; set; }

}

In DbModel, I myself store the Id. What could be the problem?

Answer:

The problem was in the libraries themselves and the author fixed this bug. The link is the same problem, where you can see the commit that solved the problem. https://github.com/linq2db/linq2db/issues/240 .

Scroll to Top