コード例 #1
0
        public async Task SaveChangesAsync(PropertyDictionaryItem[] dictItems)
        {
            if (dictItems == null)
            {
                throw new ArgumentNullException(nameof(dictItems));
            }

            var pkMap = new PrimaryKeyResolvingMap();

            using (var repository = _repositoryFactory())
            {
                var dbExistEntities = await repository.GetPropertyDictionaryItemsByIdsAsync(dictItems.Where(x => !x.IsTransient()).Select(x => x.Id).ToArray());

                foreach (var dictItem in dictItems)
                {
                    var originalEntity = dbExistEntities.FirstOrDefault(x => x.Id == dictItem.Id);
                    var modifiedEntity = AbstractTypeFactory <PropertyDictionaryItemEntity> .TryCreateInstance().FromModel(dictItem, pkMap);

                    if (originalEntity != null)
                    {
                        modifiedEntity.Patch(originalEntity);
                    }
                    else
                    {
                        repository.Add(modifiedEntity);
                    }
                }

                await repository.UnitOfWork.CommitAsync();

                pkMap.ResolvePrimaryKeys();
            }

            DictionaryItemsCacheRegion.ExpireRegion();
        }
コード例 #2
0
        public async Task DeleteAsync(string[] ids)
        {
            using (var repository = _repositoryFactory())
            {
                var dbEntities = await repository.GetPropertyDictionaryItemsByIdsAsync(ids);

                foreach (var dbEntity in dbEntities)
                {
                    repository.Remove(dbEntity);
                }
                await repository.UnitOfWork.CommitAsync();
            }

            DictionaryItemsCacheRegion.ExpireRegion();
        }
コード例 #3
0
        public Task <PropertyDictionaryItem[]> GetByIdsAsync(string[] ids)
        {
            var cacheKey = CacheKey.With(GetType(), "GetByIdsAsync", string.Join(",", ids));

            return(_platformMemoryCache.GetOrCreateExclusive(cacheKey, async(cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(DictionaryItemsCacheRegion.CreateChangeToken());
                PropertyDictionaryItem[] result;

                using (var repository = _repositoryFactory())
                {
                    //Optimize performance and CPU usage
                    repository.DisableChangesTracking();

                    result = (await repository.GetPropertyDictionaryItemsByIdsAsync(ids))
                             .Select(x => x.ToModel(AbstractTypeFactory <PropertyDictionaryItem> .TryCreateInstance()))
                             .ToArray();
                }
                return result;
            }));
        }