IT小易
2019-08-27 13:19
采纳率: 33.3%
浏览 501

asp.net core+EF架构查询数据库时报错

asp.net core+EF架构查询数据库时报错
Entities代码

[Table("Dictionary")]
    [Serializable]
    public partial class Dictionary
    {
        /// <summary>
        /// 数据字典ID
        /// </summary>
        public Guid Id { get; set; }

        /// <summary>
        /// 字典名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 字典编码
        /// </summary>
        public string Code { get; set; }

        /// <summary>
        /// 数据类型
        /// </summary>
        public int? Type { get; set; }

        /// <summary>
        /// 父级ID
        /// </summary>
        public Guid Pid { get; set; }

        /// <summary>
        /// 排序权重
        /// </summary>
        public int? Sort { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        public bool Enabled { get; set; }

        /// <summary>
        /// 是否删除
        /// </summary>
        public bool Deleted { get; set; }

        /// <summary>
        /// 创建用户ID
        /// </summary>
        public Guid CreateId { get; set; }

        /// <summary>
        /// 创建日期
        /// </summary>
        public DateTime? CreateTime { get; set; }

        /// <summary>
        /// 更新用户ID
        /// </summary>
        public Guid UpdateId { get; set; }

        /// <summary>
        ///更新日期 
        /// </summary>
        public DateTime? UpdateTime { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }
    }
上下文代码

public class EntityDbContext : DbContext
    {
        public EntityDbContext(DbContextOptions options) : base(options)
        {

        }
        public DbSet<Category> Categories { get; set; }
        public DbSet<SysUser> SysUsers { get; set; }
        public DbSet<SysUserToken> SysUserTokenes { get; set; }
        public DbSet<SysUserLoginLog> SysUserLoginLogs { get; set; }
        public DbSet<SysUserRole> SysUserRoles { get; set; }
        public DbSet<SysPermission> SysPermissions { get; set; }
        public DbSet<Dictionary> Dictionaries { get; set; }
    }

        调用代码
        private IRepository<Entities.Dictionary> _dictionaryRepository;
        private IHttpContextAccessor _accessor;

        public DictionaryService(IRepository<Entities.Dictionary> dictionaryRepository, IHttpContextAccessor accessor)
        {
            this._dictionaryRepository = dictionaryRepository;
            this._accessor = accessor;
        }
        /// <summary>
        /// 获取所有数据字典并缓存
        /// </summary>
        /// <returns></returns>
        public List<Entities.Dictionary> getAll()
        {
            var result = _dictionaryRepository.Table.Where(o => !o.Deleted);
            var ex = result.Expression;
            //result = result.Where(o => o.Code == "KGJ-2019-T-001" || o.Code == "KGJ-2019-T-002");
            //return result.OrderBy(o => o.Type).ThenBy(o => o.CreateTime).ToList();
            throw new NotImplementedException(ex.ToString());
        }

报错问题:图片说明

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • threenewbee 2019-08-27 13:35
    已采纳

    throw new NotImplementedException(ex.ToString());
    这个去掉。

    已采纳该答案
    打赏 评论
  • hxycsdn9159 2019-08-27 13:34

    getAll函数最后一行不是你自己Throw了一个exception吗?你这个函数是要返回一个list,而不是最后抛出一个异常出来,报的错就是你自己故意抛出来的异常造成的

    打赏 评论

相关推荐 更多相似问题