using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Hncore.Infrastructure.DDD; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore.ChangeTracking; namespace Hncore.Infrastructure.EF { public class RepositoryBase : IRepository where TEntity : Entity { protected DbContext Dbcontext; public RepositoryBase(IRepositoryDbContext dbContext) { Dbcontext = dbContext.DbContext; } public TEntity FindById(TId id) { return Dbcontext.Set().Find(id); } public Task FindByIdAsync(TId id) { return Dbcontext.Set().FindAsync(id); } public void Add(TEntity entity) { Dbcontext.Set().Add(entity); } public Task AddAsync(TEntity entity) { return Dbcontext.Set().AddAsync(entity); } /// /// 批量添加 /// /// public void AddRange(List entity) { Dbcontext.Set().AddRange(entity); } /// /// 批量添加 /// /// public Task AddRangeAsync(List entity) { return Dbcontext.Set().AddRangeAsync(entity); } /// /// 批量修改 /// /// public void UpdateRange(List entity) { Dbcontext.Set().UpdateRange(entity); } /// /// 批量删除 /// /// public void RemoveRange(List entity) { Dbcontext.Set().RemoveRange(entity); } public void Remove(TEntity entity) { Dbcontext.Set().Remove(entity); } public void Update(TEntity entity) { Dbcontext.Set().Update(entity); } public IQueryable GetQueryable() { return Dbcontext.Set(); } } }