EFCore 使用 JSON Column 时抛异常 "Collection was of a fixed size" 错误的解决办法
当字段被设置为 JSON Column 时,如果这个字段里面包含数组,就会抛出这个异常,需要改成 List。
相关 Issue:https://github.com/dotnet/efcore/issues/24497
例如:
public class Blog
{
public int Id { get; set; }
public BlogMeta[] Meta { get; set; } // 抛出异常!需要改为 List
}
[ComplexType]
public class BlogMeta
{
public string Title { get; set; }
public string Content { get; set; }
}
当调用 DbSet.Add() 时就会抛出异常,将 Meta 改为 List
浙公网安备 33010602011771号