Пример #1
0
        private EfMappingViewCache CreateEfMappingViewCache()
        {
            var views = _mappingViewsFileStore.Load();

            if (views == null)
            {
                _logger.Warning(() => $"Pre-generated mapping views not found. This will result in slower startup performance.");
                return(null);
            }

            return(new EfMappingViewCache(views));
        }
Пример #2
0
        private void GenerateAndSaveViews()
        {
            var sw = Stopwatch.StartNew();

            var mappingCollection = (StorageMappingItemCollection)_metadataWorkspaceFileProvider.MetadataWorkspace.GetItemCollection(DataSpace.CSSpace);
            var hash = mappingCollection.ComputeMappingHashValue();

            _performanceLogger.Write(sw, () => $"Calculated hash for current model.");
            string additionalHash = _efMappingViewsHash.GetAdditionalHash();

            _performanceLogger.Write(sw, () => $"Calculated additional hash.");

            var currentViewCache = _efMappingViewsFileStore.Load();

            if (!string.IsNullOrEmpty(currentViewCache?.Hash) &&
                currentViewCache.Hash == hash &&
                currentViewCache.AdditionalHash == additionalHash)
            {
                _logger.Trace(() => $"Hash not changed. View cache is valid. Skipping generation.");
                return;
            }

            sw.Restart();
            var errors   = new List <EdmSchemaError>();
            var newViews = mappingCollection.GenerateViews(errors)
                           .ToDictionary(a => EfMappingViewCache.GetExtentKey(a.Key), a => a.Value.EntitySql);

            foreach (var edmSchemaError in errors)
            {
                _logger.Warning(() => $"{edmSchemaError}");
            }

            var newViewCache = new EfMappingViews {
                Hash = hash, Views = newViews, AdditionalHash = additionalHash
            };

            _performanceLogger.Write(sw, () => $"Generated new views. Old hash != new hash ('{currentViewCache?.Hash}' != '{hash}').");

            _efMappingViewsFileStore.Save(newViewCache);
        }