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.

Unable to use LTree type in the entity

See original GitHub issue

I am using

"Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.0-rc.1"
"Microsoft.EntityFrameworkCore.Tools" Version="6.0.0-rc.1.21452.10"

Here is my entity class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

namespace LtreePoc.Models
{
    public class Node
    {
        public Guid Id { get; set; }
        public LTree Path { get; set; }
        public string Name { get; set; }
    }
}

Here is the DB context class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using LtreePoc.Models;

namespace LtreePoc
{
    public class NodeContext : DbContext
    {
        private const string PostgresConnectionString =
           "*****************Masked******************";

        public NodeContext()
        {

        }
        public NodeContext(DbContextOptions options)
            : base(options)
        {
        }

        public DbSet<Node> Nodes { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasPostgresExtension("ltree");

        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseNpgsql(PostgresConnectionString);
        }
    }
}

Here is my snippet trying to add a Node to my database.

     var node = new Node
      {
          Name = "xyz",
          Path = new LTree("a")
      };
      await _context.Nodes.AddAsync(node);
      _context.SaveChanges();

Here is the screen shot in VS 2022 … while debugging.

image

Here is the exception that is thrown

Microsoft.EntityFrameworkCore.DbUpdateException
  HResult=0x80131500
  Message=An error occurred while saving the entity changes. See the inner exception for details.
  Source=Microsoft.EntityFrameworkCore.Relational
  StackTrace:
   at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IList`1 entries)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IList`1 entriesToSave)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(StateManager stateManager, Boolean acceptAllChangesOnSuccess)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<>c.<SaveChanges>b__103_0(DbContext _, ValueTuple`2 t)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges()
   at LtreePoc.Program.<AddNode>d__5.MoveNext() in C:\_Nithin\Src\Play\efcore_ltree\LtreePoc\Program.cs:line 50
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at LtreePoc.Program.<Main>d__3.MoveNext() in C:\_Nithin\Src\Play\efcore_ltree\LtreePoc\Program.cs:line 27

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
PostgresException: 42883: no binary input function available for type ltree

I am struggling to understand the issue here. Unable to get any help online.

Please let me know where I am going wrong?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rojicommented, Oct 5, 2021

You’re probably using a version of PostgreSQL older than 13; Npgsql relies on ltree binary support, which was added in 13 only. I’ll add a note in the docs.

0reactions
f2002642commented, Oct 6, 2021

@roji Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ltree postgres type using spring data jpa -- geting syntax ...
When attempting to write an entity containing a value of ltree type, I was getting the following error: column "path" is of type...
Read more >
Postgres ltree extension · Issue #4193 · typeorm ...
Ltree let's you use the column type "ltree". Currently Typeorm does not support it as it seems. Is there a plan to support...
Read more >
LTREE extension does not exist after CREATE EXTENSION
This is a snippet of the trigger and the problem seems to be happeing when I declare a variable of type ltree: CREATE...
Read more >
Documentation: 15: F.23. ltree
This module implements a data type ltree for representing labels of data stored in a hierarchical tree-like structure. Extensive facilities for searching ...
Read more >
Installing the Postgres LTREE Extension
This error means the LTREE code isn't even installed on your Postgres server. If you're running on Linux and installed Postgres using a...
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