Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LTree column type doens worked with migration #3226

Open
sentaniel opened this issue Jul 14, 2024 · 0 comments
Open

LTree column type doens worked with migration #3226

sentaniel opened this issue Jul 14, 2024 · 0 comments

Comments

@sentaniel
Copy link

sentaniel commented Jul 14, 2024

Hello. I have next entity class

public class OrganizationModule
{
    public int Id { get; set; }
    public int OldSystemId { get; set; }
    public string Name { get; set; } = null!;
    public ModuleType Type { get; set; }
    public LTree Path { get; set; }
}

with this EntityConfig class

  public void Configure(EntityTypeBuilder<OrganizationModule> builder)
   {
       builder.HasKey(x => x.Id);
       
       builder.Property(x => x.Name).HasMaxLength(200).IsRequired();
       builder.Property(x => x.Path).HasColumnType("ltree");
       builder.HasIndex(treeItem => treeItem.Path).HasMethod("gist"); 
   }

It`s generated this migration

            migrationBuilder.AddColumn<string>(
                name: "Path",
                table: "OrganizationModules",
                type: "ltree",
                nullable: false,
                defaultValue: "");

            migrationBuilder.CreateIndex(
                name: "IX_OrganizationModules_Path",
                table: "OrganizationModules",
                column: "Path")
                .Annotation("Npgsql:IndexMethod", "gist");

But in db snapshot class we have this:

                    b.Property<string>("Path")
                        .IsRequired()
                        .HasColumnType("ltree");

and when I will try get any data. I have this error:
"Exception occurred: The 'LTree' property 'OrganizationModule.Path' could not be mapped to the
database type 'ltree' because the database provider does not support mapping 'LTree' properties to 'ltree' columns. Consider mapping to a different database type or converting the property value to a
type supported by the database using a value converter. See https://aka.ms/efcore-docs-value-converters for more information. Alternately, exclude the property from the model using the '[NotMapped]' attribute or by usi
ng 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant