Exemple #1
0
        protected virtual IQueryable <TEntity> FetchEntities(TKey id = default(TKey))
        {
            var queryable = DbContext.Set <TEntity>().AsQueryable();

            if (!IsUnspecified(id))
            {
                queryable = queryable.FindId(id);
            }
            queryable = Filter(queryable);
            return(queryable);
        }
Exemple #2
0
        public static async Task BuildCache <TEntity, TCache>(TreasureEntities entities, IMapper mapper, CacheItemType type, DateTimeOffset timestamp) where TEntity : class
        {
            Debug.WriteLine("Building cache for " + type);
            var data = entities.Set <TEntity>().AsQueryable();
            var cast = await data.ProjectTo <TCache>(mapper.ConfigurationProvider).ToListAsync();

            var json = JsonConvert.SerializeObject(cast, JsonSettings);

            var existing = await entities.CacheSets.SingleOrDefaultAsync(x => x.Type == type);

            var existed = existing != null;

            if (!existed)
            {
                existing = new CacheSet
                {
                    Type = type
                };
                entities.CacheSets.Add(existing);
            }
            existing.JSON       = json;
            existing.EditedDate = timestamp;
            await entities.SaveChangesAsync();

            Debug.WriteLine("Cache built.");
        }