/// <summary> /// 添加 /// </summary> /// <param name="entity">要添加的实体</param> /// <returns>是否添加成功</returns> public bool Add(TEntity entity) { try { _logger.LogInformation($" {this.GetType().Name} 添加信息"); _db.Set <TEntity>().Add(entity); return(_db.SaveChanges() > 0); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(false); } }
/// <summary> /// 构造函数 /// </summary> /// <param name="dbContext">数据上下文</param> /// <param name="logger">日志</param> protected BaseRepository(ISTDbContext dbContext, ILogger <TEntity> logger) { _logger = logger; _db = dbContext; _dbSet = _db.Set <TEntity>(); }