Skip to content

support for dotnet ef dbcontext scaffold #44

Closed

Description

@bangonkali

Hi! First of all, this is an awesome project. Thank you very much for making it available.

I would like to know if ef-core scaffolding is supported or planned to be supported. I'm trying to scaffold a table with a halfvec(3072) column and it's not working. I have the following table:

create table "memory-default"
(
    _pk       text                                          not null
        primary key,
    embedding halfvec(3072),
    labels    text[]                   default '{}'::text[] not null,
    chunk     text                     default ''::text     not null,
    extras    jsonb                    default '{}'::jsonb  not null,
    my_field1 text                     default ''::text,
    _update   timestamp with time zone default CURRENT_TIMESTAMP
);

alter table "memory-default"
    owner to postgres;

create index "memory-default_labels_idx"
    on "memory-default" using gin (labels);

create index "memory-default_embedding_idx"
    on "memory-default" using hnsw (embedding halfvec_cosine_ops);

I tried executing the following command:

dotnet ef dbcontext scaffold \
  --project src/MyProject.Core/MyProject.Core.csproj \
  --startup-project src/MyProject.Core/MyProject.Core.csproj \
  --data-annotations \
  --context MyProjectContext \
  --force \
  --output-dir Data/Entities \
  --namespace MyProject.Core.Entities \
  --context-namespace  MyProject.Core.Data \
  --context-dir Data \
  --no-onconfiguring \
  "Host=postgres;Port=5432;Username=postgres;Password=password;Database=myproject" \
  Npgsql.EntityFrameworkCore.PostgreSQL

And I got the following error:

Build started...
Build succeeded.
Could not load database collations.
Could not find type mapping for column 'public.memory-default.embedding' with data type 'halfvec(3072)'. Skipping column.
Unable to scaffold the index 'memory-default_embedding_idx'. The following columns could not be scaffolded: embedding.

The generated output only goes as far as the following in the DBContext:

public virtual DbSet<MemoryDefault> MemoryDefaults { get; set; }

And for the model iteself the output is:

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using NodaTime;

namespace MyProject.Core.Entities;

[Table("memory-default")]
public partial class MemoryDefault
{
    [Key]
    [Column("_pk")]
    public string Pk { get; set; } = null!;

    [Column("labels")]
    public List<string> Labels { get; set; } = null!;

    [Column("chunk")]
    public string Chunk { get; set; } = null!;

    [Column("extras", TypeName = "jsonb")]
    public string Extras { get; set; } = null!;

    [Column("my_field1")]
    public string? MyField1 { get; set; }

    [Column("_update")]
    public Instant? Update { get; set; }
}

Btw, I'm using the NodaTime library for the Instant type. In the case of the Instant type NodaTime was able to replace the timestamp with time zone type from sql.

Maybe there is a way to implement proper mapping as well for scaffolding as NodaTime has?

Activity

  1. roji commented on Nov 13, 2024

    @roji
    Contributor

    Yeah, this shouldn't be too hard to do - I'll try to take care of this soon.

  2. bangonkali commented on Nov 14, 2024

    @bangonkali
    Author

    Thanks @roji! 🙏 I have no background at the moment at this level of programming extensions/plugins with dotnet and efcore but I'm really interested myself to understand how this is going to be implemented. Looking forward to this.

  3. added 4 commits that reference this issue on Mar 24, 2025
    efac015
    641dc11
    df46511
    990f420
  4. ankane commented on Mar 26, 2025

    @ankane
    Member

    This was added in the commit above (thanks to @roji) and will be part of Pgvector.EntityFrameworkCore 0.2.2. Thanks for the suggestion @bangonkali!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions