C# 使用Abp仓储访问数据库时报错记录集

1.报错 The JSON value could not be converted to Volo.Abp.Data.ExtraPropertyDictionary.

 1.2 解决方法1,在属性字段中增加数据契约标签DataContract,数据成员标签DataMember

1.3 解决方法二,去掉上面的数据标签,由于原来的实体类继承自集合根AggregateRoot,改成继承自Entity ,并且实现GetKeys方法

由于Entity 默认的Id是自增的,所以实现GetKeys 方法时,要这样处理。

public class UserRole : Entity
{
    public virtual int Id{ get; protected set; }

    public UserRole()
    {
            
    }
    
    public override object[] GetKeys()
    {
        return new object[] { Id };
    }
}

2. 报错上下文实例被释放的问题

2.1 解决方法:在程序的报错方法贴上一个 UnitOfWork 标签

public class MyHandler:ITransientDependency
 {
       [UnitOfWork]
        public async Task HandleEventAsync()
        {
           
        }
 }

 以上基本解决了我的出现的问题。

猜你喜欢

转载自blog.csdn.net/weixin_39237340/article/details/125971108
今日推荐