首页 > 其他分享 >The property '***' is not a String or Byte array. Length can only be configured for String

The property '***' is not a String or Byte array. Length can only be configured for String

时间:2023-03-22 12:34:38浏览次数:32  
标签:... String configured only StringLength Byte array


The property '*' is not a String or Byte array. Length can only be configured for String and Byte array properties的问题解决

在EntityFramework中执行Migration操作时报错

The property '*' is not a String or Byte array. Length can only be configured for String and Byte array properties

发现时Model类Property设置了不当的Stringlength导致的

比如如下两种情况

不当的设置int的StringLength

[Required] 
//[MaxLength(1)]
public int Private { get; set; }

不当的为bool设置StringLength

[Required]
//[StringLength(50)]
public bool IsActive { get; set; }

解决办法

如上代码所示,把不当设置的StringLength取消就可以正常操作了

标签:...,String,configured,only,StringLength,Byte,array
From: https://blog.51cto.com/dupeng0811/6142393

相关文章