使用 SqlSugar 生成 MySQL 数据库时将列名转换为小写
可以使用 SqlSugar 生成数据库时通过设置参数来将列名转为小写。具体方法如下:
- 在生成数据库的代码中添加以下语句:
var db = new MySqlSugarClient(new ConnectionConfig()
{
ConnectionString = 'your connection string',
DbType = DbType.MySql,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute,
ConfigureExternalServices = new ConfigureExternalServices()
{
EntityService = (property, column) =>
{
column.ColumnName = column.ColumnName.ToLower();
}
}
});
- 在上面的代码中,通过配置 ConfigureExternalServices 参数来设置 EntityService 回调函数。在 EntityService 回调函数中,将 column.ColumnName 转为小写即可。
这样,在生成数据库时,所有列名都会被转为小写了。
原文地址: https://www.cveoy.top/t/topic/oDEF 著作权归作者所有。请勿转载和采集!