/// <summary> /// Call the View Generator's Generate view method /// and collect the Views and store it in a local dictionary. /// </summary> /// <param name="entityContainerMap"></param> /// <param name="resultDictionary"></param> private void SerializedGenerateViews(StorageEntityContainerMapping entityContainerMap, Dictionary <EntitySetBase, GeneratedView> resultDictionary) { //If there are no entity set maps, don't call the view generation process Debug.Assert(entityContainerMap.HasViews); ViewGenResults viewGenResults = ViewgenGatekeeper.GenerateViewsFromMapping(entityContainerMap, m_config); KeyToListMap <EntitySetBase, GeneratedView> extentMappingViews = viewGenResults.Views; if (viewGenResults.HasErrors) { // Can get the list of errors using viewGenResults.Errors throw new MappingException(Helper.CombineErrorMessage(viewGenResults.Errors)); } foreach (KeyValuePair <EntitySetBase, List <GeneratedView> > keyValuePair in extentMappingViews.KeyValuePairs) { //Multiple Views are returned for an extent but the first view //is the only one that we will use for now. In the future, //we might start using the other views which are per type within an extent. GeneratedView generatedView; //Add the view to the local dictionary if (!resultDictionary.TryGetValue(keyValuePair.Key, out generatedView)) { generatedView = keyValuePair.Value[0]; resultDictionary.Add(keyValuePair.Key, generatedView); } } }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] // referenced by System.Data.Entity.Design.dll internal Dictionary <EntitySetBase, string> GenerateEntitySetViews(out IList <EdmSchemaError> errors) { Dictionary <EntitySetBase, string> esqlViews = new Dictionary <EntitySetBase, string>(); errors = new List <EdmSchemaError>(); foreach (var mapping in GetItems <Map>()) { var entityContainerMapping = mapping as StorageEntityContainerMapping; if (entityContainerMapping != null) { // If there are no entity set maps, don't call the view generation process. if (!entityContainerMapping.HasViews) { return(esqlViews); } // If entityContainerMapping contains only query views, then add a warning to the errors and continue to next mapping. if (!entityContainerMapping.HasMappingFragments()) { Debug.Assert(2088 == (int)StorageMappingErrorCode.MappingAllQueryViewAtCompileTime, "Please change the ERRORCODE_MAPPINGALLQUERYVIEWATCOMPILETIME value as well"); errors.Add(new EdmSchemaError( Strings.Mapping_AllQueryViewAtCompileTime(entityContainerMapping.Identity), (int)StorageMappingErrorCode.MappingAllQueryViewAtCompileTime, EdmSchemaErrorSeverity.Warning)); } else { ViewGenResults viewGenResults = ViewgenGatekeeper.GenerateViewsFromMapping(entityContainerMapping, new ConfigViewGenerator() { GenerateEsql = true }); if (viewGenResults.HasErrors) { ((List <EdmSchemaError>)errors).AddRange(viewGenResults.Errors); } KeyToListMap <EntitySetBase, GeneratedView> extentMappingViews = viewGenResults.Views; foreach (KeyValuePair <EntitySetBase, List <GeneratedView> > extentViewPair in extentMappingViews.KeyValuePairs) { List <GeneratedView> generatedViews = extentViewPair.Value; // Multiple Views are returned for an extent but the first view // is the only one that we will use for now. In the future, // we might start using the other views which are per type within an extent. esqlViews.Add(extentViewPair.Key, generatedViews[0].eSQL); } } } } return(esqlViews); }
/// <summary> /// Generates a single query view for a given Extent and type. It is used to generate OfType and OfTypeOnly views. /// </summary> /// <param name="includeSubtypes">Whether the view should include extents that are subtypes of the given entity</param> private bool TryGenerateQueryViewOfType(EntityContainer entityContainer, EntitySetBase entity, EntityTypeBase type, bool includeSubtypes, out GeneratedView generatedView) { Debug.Assert(entityContainer != null); Debug.Assert(entity != null); Debug.Assert(type != null); if (type.Abstract) { generatedView = null; return(false); } //Get the mapping that has the entity container mapped. StorageEntityContainerMapping entityContainerMap = MappingMetadataHelper.GetEntityContainerMap(m_storageMappingItemCollection, entityContainer); Debug.Assert(!entityContainerMap.IsEmpty, "There are no entity set maps"); bool success; ViewGenResults viewGenResults = ViewgenGatekeeper.GenerateTypeSpecificQueryView(entityContainerMap, m_config, entity, type, includeSubtypes, out success); if (!success) { generatedView = null; return(false); //could not generate view } KeyToListMap <EntitySetBase, GeneratedView> extentMappingViews = viewGenResults.Views; if (viewGenResults.HasErrors) { throw new MappingException(Helper.CombineErrorMessage(viewGenResults.Errors)); } Debug.Assert(extentMappingViews.AllValues.Count() == 1, "Viewgen should have produced only one view"); generatedView = extentMappingViews.AllValues.First(); return(true); }