Skip to content

support for dotnet ef dbcontext scaffold #44

@bangonkali

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?

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