Skip to content

开启UseAutoSyncStructure 表结构自动同步的问题 #2242

@shengshengbieli-gif

Description

@shengshengbieli-gif

配置连接字符串的时候指定 searchpath=dbo;

我的实体是 [Table(Name = "nursing_daily_detail")],没有 schema 前缀。所以:

运行时 CRUD:FreeSql 生成的 SQL 是 ... FROM nursing_daily_detail(裸表名)。PostgreSQL 收到后,按 search_path=dbo 去解析 → 命中 dbo.nursing_daily_detail

UseAutoSyncStructure 在读表结构时,自己拼了一段元数据查询里面显式写死了 schema 条件:

where ns.nspname = 'public' and c.relname = 'nursing_daily_detail'

FreeSql 用写死的 nspname='public' 去读结构 → 读到 public.nursing_daily_detail导致了alter table的时候报错跟c#实体里面类型不一致

总结来说就是:

连接字符串里的search_path 决定"数据库执行时怎么找表";FreeSql 的结构同步用的是"自己写死 public 的元数据查询",两者不是一回事。所以裸表名运行时走 dbo,同步时却去读 public

不知道 算不算BUG 感觉很奇怪-.-

postgresql

FreeSql postgresql 3.5.213

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions