public IEnumerable <T> Execute(bool includeDeleted = false) { if (typeof(ISoftEntity).IsAssignableFrom(typeof(T)) && !includeDeleted) { return(_context.Set <T>().Where(x => !(x as ISoftEntity).IsDeleted)); } else { return(_context.Set <T>()); } }
public virtual bool Delete(TEntity entity) { if (entity == null) { throw new Exception("删除对象不能为空"); } CoreContext.Set <TEntity>().Remove(entity); return(CoreContext.SaveChanges() > 0); }
/// <summary> /// 插入并返回最新对象 /// </summary> /// <param name="entity"></param> /// <returns></returns> public virtual TEntity InsertReturnEntity(TEntity entity) { if (entity == null) { throw new Exception("新增对象不能为空"); } CoreContext.Set <TEntity>().Add(entity); CoreContext.SaveChanges(); return(entity); }
public Processes GetProcess(string connectionString, int processId) { using (var entityContext = new CoreContext(connectionString)) { var query = from e in entityContext.Set <Processes>() select e; var entitiy = query.Where(c => c.ProcessId == processId).FirstOrDefault(); return(entitiy); } }
public ExtractionJob GetExtractionJob(string connectionString, string code) { using (var entityContext = new CoreContext(connectionString)) { var query = from e in entityContext.Set <ExtractionJob>() select e; var job = query.Where(c => c.Code == code).FirstOrDefault(); return(job); } }
public List <ExtractionJob> GetNewOrPendingExtractionJobs(string connectionString) { using (var entityContext = new CoreContext(connectionString)) { var query = from e in entityContext.Set <ExtractionJob>() select e; var jobs = query.Where(c => c.Status == PackageStatus.New || c.Status == PackageStatus.Pending); return(jobs.ToList()); } }
public List <ExtractionJob> GetExtractionJobsToStop(string connectionString) { using (var entityContext = new CoreContext(connectionString)) { var query = from e in entityContext.Set <ExtractionJob>() select e; var jobs = query.Where(c => c.Status == PackageStatus.Stop || c.Status == PackageStatus.Done || c.Status == PackageStatus.Fail); return(jobs.ToList()); } }
public List <ExtractionTrigger> GetExtractionTriggers(string connectionString, int jobId) { using (var entityContext = new CoreContext(connectionString)) { var query = from e in entityContext.Set <ExtractionTrigger>() select e; var entities = query.Where(c => c.ExtractionJobId == jobId).ToList(); return(entities); } }
public Extraction GetExtraction(string connectionString, int extractionId) { using (var entityContext = new CoreContext(connectionString)) { var query = from e in entityContext.Set <Extraction>() select e; var entitiy = query.Where(c => c.ExtractionId == extractionId).FirstOrDefault(); return(entitiy); } }
public void Add(TEntityDTO entity) { var mappedEntity = Mapper.Map <TEntity>(entity); Db.Set <TEntity>().Add(mappedEntity); Db.SaveChanges(); }
public void UpdateProcessTrigger(string connectionString, ProcessTrigger trigger) { using (var entityContext = new CoreContext(connectionString)) { var existingEntity = (from e in entityContext.Set <ProcessTrigger>() where e.ProcessTriggerId == trigger.ProcessTriggerId select e).FirstOrDefault(); SimpleMapper.PropertyMap(trigger, existingEntity); entityContext.SaveChanges(); } }
public void UpdateExtractionJob(string connectionString, ExtractionJob job) { using (var entityContext = new CoreContext(connectionString)) { var existingEntity = (from e in entityContext.Set <ExtractionJob>() where e.ExtractionJobId == job.ExtractionJobId select e).FirstOrDefault(); SimpleMapper.PropertyMap(job, existingEntity); entityContext.SaveChanges(); } }
public virtual bool Insert(TEntity entity) { try { if (entity == null) { throw new Exception("新增对象不能为空"); } CoreContext.Set <TEntity>().Add(entity); return(CoreContext.SaveChanges() > 0); } catch (DbEntityValidationException ex) { return(false); } }
/// <summary> /// Returns all the active registries from the database /// </summary> /// <returns>List of Entities</returns> public virtual IQueryable <TEntity> GetAllActive() { return(Context.Set <TEntity>().Where(x => x.Active)); }
protected RepoBase() { Db = new CoreContext(); Table = Db.Set <T>(); }
protected RepoBase(DbContextOptions <CoreContext> options) { Db = new CoreContext(options); Table = Db.Set <T>(); }
protected Repository(CoreContext context) { Db = context; DbSet = Db.Set <TEntity>(); }
public BaseRepository(CoreContext context) { _context = context; _dbSet = context.Set <TEntity>(); }
public virtual int Count(Expression <Func <TEntity, bool> > expression) { return(CoreContext.Set <TEntity>().Count(expression)); }
public virtual async Task <IEnumerable <T> > GetAllAsync() { return(await _context.Set <T>().ToListAsync()); }
public virtual IQueryable <TEntity> Find(Expression <Func <TEntity, bool> > expression) { return(CoreContext.Set <TEntity>().Where(expression)); }
protected Repository(CoreContext db) { Db = db; DbSet = Db.Set <TEntity>(); Connection = Db.Database.GetDbConnection(); }
public virtual bool Insert(IEnumerable <TEntity> batch) { CoreContext.Set <TEntity>().AddRange(batch); return(CoreContext.SaveChanges() > 0); }
protected override CommandResult <ProductData> OnExecute(object commandParameter) { var result = new CommandResult <ProductData>(); var param = commandParameter as LoadBookProductDetailParameter; using (CoreContext context = new CoreContext()) { var bookConfig = new BookUtil(); if (bookConfig._Config == null) { result.ErrorCode = -1; result.ErrorMessage = "活动已结束"; return(result); } if (DateTime.Now < bookConfig._Config.StartTime) { result.ErrorCode = -1; result.ErrorMessage = "活动未开始"; return(result); } if (bookConfig._Config.EndTime < DateTime.Now) { result.ErrorCode = -1; result.ErrorMessage = "活动已结束"; return(result); } var pmodel = bookConfig._ProductConfig.Where(p => p.ProductNo == param.ProductNo).FirstOrDefault(); if (pmodel == null) { result.ErrorCode = -1; result.ErrorMessage = "产品对象为空"; return(result); } var productInfo = context.ProductInfo.Where(p => p.ProductNo == pmodel.ProductNo).FirstOrDefault(); var pinfo = context.Set <ShopProductInfo>().FromSql($@"select * from shop_product_info where product_no ={pmodel.ProductNo}").FirstOrDefault(); if (pinfo != null) { pmodel.ProductImage = pinfo.ProductImg; pmodel.Description = pinfo.Description; pmodel.ThumbnailImg = pinfo.ThumbnailImg; } if (productInfo != null) { if (!string.IsNullOrEmpty(productInfo.ProductName)) { pmodel.ProductName = productInfo.ProductName; } if (!string.IsNullOrEmpty(productInfo.ProductDesc)) { pmodel.ShortDesc = productInfo.ProductDesc; } if (!string.IsNullOrEmpty(productInfo.ImageUrl)) { pmodel.ThumbnailImg = productInfo.ImageUrl; } } result.Data = pmodel; } return(result); }
public RepositoryBase(CoreContext context) { Context = context; DbSet = Context.Set <TEntity>(); }
public BaseRepository(CoreContext context) { Context = context; this.DbSet = Context.Set <T>(); }
public Driver() { this.dbContext = new CoreContext(); this.dbSet = dbContext.Set <TEntity>(); }
public virtual async Task <T> FindAsync(object[] keys, CancellationToken cancellationToken) { var entity = await _contexto.Set <T>().FindAsync(keys, cancellationToken); return(entity); }
public virtual bool Delete(IEnumerable <TEntity> batch) { CoreContext.Set <TEntity>().RemoveRange(batch); return(CoreContext.SaveChanges() > 0); }
public async Task CreateAsync(T entity) { await _context.Set <T>().AddAsync(entity); await _context.SaveChangesAsync(); }