自动建表时,部分Attribute无法被继承 返回

SqlSugar
7 62

SqlSugar Core 版本:5.1.4.59

数据库:Mysql 8.0

一、在Interface中对属性附加SugarColumn特性时,如果指定自增和主键,会导致继承自接口的类生成表时失败,报Drop Table的时候没有找到主键。数据库生成结果中,相应字段没有自增和主键的标识。

二、在类定义中,引入SugarIndex,无法被派生类继承。即在生成表时,并不会把继承自父类中的相关索引特性与已实现。

热忱回答7

  • 这个我要考虑一下场景,因为有的人不需要基类

    0 回复
  • SugarIndex 可以AOP全局设置的

    0 回复
  • @fate sta:有具体的教程地址么?官网的教程,没有找到SugarIndex的全局设置。

    0 回复
  •                 DbType = SqlSugar.DbType.PostgreSQL,
                    ConnectionString = Config.ConnectionString,
                    InitKeyType = InitKeyType.Attribute,
                    IsAutoCloseConnection = true,
                    ConfigureExternalServices=new ConfigureExternalServices() {
                        EntityNameService = (type, entity) => 
                        {
                              if(type逻辑)
                                entity.Indexs=new List<SugarIndexAttribute>() { }
                        }
                    }


    0 回复
  • 这样就可以不用特性全局设置了

    0 回复
  • EntityNameService = (type, entity) => 
    {
      //修改表        
    },
    EntityService = (type, column) => 
    {
       //修改列
    }


    0 回复
  • @fate sta:谢谢,问题解决了,索引无法追加的问题,可能是因为继承的时候,如果没特殊设置,那么所有的派生索引名称都是一样的,可能sqlsugar内部有去重机制,通过AOP的过滤,追加上前缀,就OK了

    0 回复