Closed AtlantisDe closed 10 months ago
column.DataType = "text"; 应该是 DateType
名字和SugarColumn有点不一样
名字和SugarColumn有点不一样
这个我试过了还是不行呢 column.DataType = "text"; 应该是 DateType
这个是建表用的, 不清楚你想要什么
column.DataType=StaticConfig.CodeFirst_BigString 大文本用这个
如果是普通的字符串不需要设置column.DataType 只要设置Length=255
https://www.donet5.com/Home/Doc?typeId=2366 还有问题按模版提供可以让我看懂你是什么问题的DEMO
现在我根本不知道你要什么,你在问题在哪儿
你是要设置数据库的类型,还是要设置SqlParameter的 DbType
你是要设置数据库的类型,还是要设置SqlParameter的 DbType
我要设置数据库表里面的字段类型 比如
[SugarColumn(ColumnDataType = "text", IsNullable = true)]
public class MyTable
{
[SugarColumn(ColumnDataType = "longtext")]
public string LongTextColumn { get; set; }
[SugarColumn(ColumnDataType = "mediumtext")]
public string MediumTextColumn { get; set; }
[SugarColumn(ColumnDataType = "text")]
public string TextColumn { get; set; }
}
默认情况下,您这边就是这样实现字段类型,配置.
因为我现在在做,自定义实体,字段类型适配时候,没法用代码去实现.
我试过了很多个字段类型
没有找到对于 ColumnDataType
//简单来说就是我希望我这边自己自定义 数据库字段类型目前我用EF 它会根据长度适配
TEXT 最大存储容量为 65,535 字节
MEDIUMTEXT 最大存储容量为 16,777,215 字节(约 16 MB)
LONGTEXT 最大存储容量为 4,294,967,295 字节(约 4 GB)
//这些类型,但是您这边库只要字符串长度大于比如 3000 就默认就是
//LONGTEXT 类型了 好像. 所以我需要做适配.
new SqlSugarClient(new ConnectionConfig()
{
DbType = SqlSugar.DbType.SqlServer,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
ConfigureExternalServices = new ConfigureExternalServices()
{
EntityService = (x, y) =>
{
if (你的特性长度)//这边可以打个断点是否进来
y.DataType = "text";
if (你的特性长度)//这边可以打个断点是否进来
y.DataType = "mediumtext";
if (你的特性长度)//这边可以打个断点是否进来
y.DataType = "longtext";
}
}
});
DataType是建表 ,记得把以前表删了才会有效
相同类型可能ORM不会更新
还有问题发完整测试用例
发完整测试用例
- 应该是之前代码有问题实际上我代码问题应该是判断出了问题
- 之前是这样 255 - 65535 判断的没成功.
var stringLengthAttribute = attributes.OfType<StringLengthAttribute>().FirstOrDefault();
if (stringLengthAttribute != null) // 设置字符串长度
{
column.Length = stringLengthAttribute.MaximumLength;
if (column.Length > 255&& column.Length <= 65535)
{
column.DataType = "text";
}
}
改为 2000 && column.Length <= 65535 --- 成功
var stringLengthAttribute = attributes.OfType<StringLengthAttribute>().FirstOrDefault();
if (stringLengthAttribute != null) // 设置字符串长度
{
column.Length = stringLengthAttribute.MaximumLength;
if (column.Length > 2000 && column.Length <= 65535)
{
column.DataType = "text";
}
}
应该是我看错了 世界我代码问题 应该看错表了.. --- 都发现成功了 ---谢谢
配置实体 自带特性 如何配置 ColumnDataType 这个属性
只能手动配置到那个属性上?
我想用代码实现去适配.