/// <summary> /// This method lets you change whether an EntityContainerMapping should generate update views or not (no means it is read-only). /// </summary> /// <param name="ecm">Must point to a valid EntityContainerMapping</param> internal ChangeEntityContainerMappingCommand(EntityContainerMapping ecm, bool generateUpdateViews) { CommandValidation.ValidateEntityContainerMapping(ecm); _ecm = ecm; _generateUpdateViews = generateUpdateViews; }
private static EntityContainerMapping BuildEntityContainerMapping(SimpleMappingContext mappingContext) { var storeEntityContainer = mappingContext.StoreModel.Containers.Single(); var entityContainerMapping = new EntityContainerMapping( mappingContext[storeEntityContainer], storeEntityContainer, null, false, false); foreach (var entitySetMapping in BuildEntitySetMappings(entityContainerMapping, mappingContext)) { entityContainerMapping.AddSetMapping(entitySetMapping); } foreach (var associationSetMapping in BuildAssociationSetMappings(entityContainerMapping, mappingContext)) { entityContainerMapping.AddSetMapping(associationSetMapping); } foreach (var mappedStoredFunction in mappingContext.MappedStoreFunctions()) { entityContainerMapping.AddFunctionImportMapping( BuildComposableFunctionMapping(mappedStoredFunction, mappingContext)); } return entityContainerMapping; }
// internal for testing internal void WriteEntityContainerMappingElement(EntityContainerMapping containerMapping) { DebugCheck.NotNull(containerMapping); _xmlWriter.WriteStartElement(MslConstructs.EntityContainerMappingElement); _xmlWriter.WriteAttributeString(MslConstructs.StorageEntityContainerAttribute, _dbSchemaName); _xmlWriter.WriteAttributeString( MslConstructs.CdmEntityContainerAttribute, containerMapping.EdmEntityContainer.Name); foreach (var set in containerMapping.EntitySetMappings) { WriteEntitySetMappingElement(set); } foreach (var set in containerMapping.AssociationSetMappings) { WriteAssociationSetMappingElement(set); } foreach (var functionMapping in containerMapping.FunctionImportMappings.OfType<FunctionImportMappingComposable>()) { WriteFunctionImportMappingElement(functionMapping); } foreach (var functionMapping in containerMapping.FunctionImportMappings.OfType<FunctionImportMappingNonComposable>()) { WriteFunctionImportMappingElement(functionMapping); } _xmlWriter.WriteEndElement(); }
internal CreateFunctionImportMappingCommand(EntityContainerMapping em, Function function, string createFuncImpCmdId) : base(PrereqId) { ContainerMapping = em; Function = function; _createFuncImpCmdId = createFuncImpCmdId; }
internal CreateFunctionImportMappingCommand(EntityContainerMapping em, Function function, FunctionImport functionImport) : base(PrereqId) { ContainerMapping = em; Function = function; FunctionImport = functionImport; }
protected override void InvokeInternal(CommandProcessorContext cpc) { // if don't have an ECM yet, go create one if (_entityContainerMapping == null) { var cmd = new CreateEntityContainerMappingCommand(_entitySet.Artifact); CommandProcessor.InvokeSingleCommand(cpc, cmd); _entityContainerMapping = cmd.EntityContainerMapping; } Debug.Assert(_entityContainerMapping != null, "_entityContainerMapping should not be null"); if (_entityContainerMapping == null) { throw new CannotLocateParentItemException(); } // create the ESM var esm = new EntitySetMapping(_entityContainerMapping, null); esm.Name.SetRefName(_entitySet); _entityContainerMapping.AddEntitySetMapping(esm); XmlModelHelper.NormalizeAndResolve(esm); _created = esm; }
internal static void ConstructEntityMappings( EntityContainerMapping ecm, AddCSideEntityTypeToEntityTypeIdentityMapping addMappingDelegate) { foreach (var esm in ecm.EntitySetMappings()) { foreach (var etm in esm.EntityTypeMappings()) { foreach (var mf in etm.MappingFragments()) { var sSideEntitySet = mf.StoreEntitySet.Target as StorageEntitySet; if (null != sSideEntitySet) { var dbObj = DatabaseObject.CreateFromEntitySet(sSideEntitySet); // record mappings to C-side entity types foreach (var entry in etm.TypeName.Entries) { if (null != entry.EntityType) { // now that we've identified EntityType/DatabaseObject pair // call the delegate that was passed in to actually do the mapping addMappingDelegate(entry.EntityType, dbObj); } } } } } } }
public void Can_get_entity_set() { var entityContainerMapping = new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)); var entitySet = new EntitySet(); var entitySetMapping = new EntitySetMapping(entitySet, entityContainerMapping); Assert.Same(entitySet, entitySetMapping.EntitySet); }
internal FunctionImportMappingComposableHelper( EntityContainerMapping entityContainerMapping, string sourceLocation, List<EdmSchemaError> parsingErrors) { _entityContainerMapping = entityContainerMapping; m_sourceLocation = sourceLocation; m_parsingErrors = parsingErrors; }
internal static ViewGenResults GenerateViewsFromMapping( EntityContainerMapping containerMapping, ConfigViewGenerator config) { CellCreator cellCreator = new CellCreator(containerMapping); List <Cell> cells = cellCreator.GenerateCells(); CqlIdentifiers identifiers = cellCreator.Identifiers; return(ViewgenGatekeeper.GenerateViewsFromCells(cells, config, identifiers, containerMapping)); }
internal CreateEntitySetMappingCommand(EntityContainerMapping entityContainerMapping, ConceptualEntitySet entitySet) { Debug.Assert(entitySet != null, "entitySet should not be null"); Debug.Assert(entitySet.Artifact != null, "entitySet's artifact should not be null"); CommandValidation.ValidateConceptualEntitySet(entitySet); _entityContainerMapping = entityContainerMapping; _entitySet = entitySet; }
public void Can_get_container_mapping() { var containerMapping = new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)); var storageSetMapping = new EntitySetMapping( new EntitySet(), containerMapping); Assert.Same(containerMapping, storageSetMapping.EntityContainerMapping); }
public void Can_get_store_and_entity_containers() { var entityContainer = new EntityContainer("C", DataSpace.CSpace); var storeContainer = new EntityContainer("S", DataSpace.CSpace); var entityContainerMapping = new EntityContainerMapping(entityContainer, storeContainer, null, false, false); Assert.Same(entityContainer, entityContainerMapping.EdmEntityContainer); Assert.Same(storeContainer, entityContainerMapping.StorageEntityContainer); }
public DynamicToFunctionModificationCommandConverter( AssociationSetModificationFunctionMapping associationSetModificationFunctionMapping, EntityContainerMapping entityContainerMapping) { DebugCheck.NotNull(associationSetModificationFunctionMapping); DebugCheck.NotNull(entityContainerMapping); _associationSetModificationFunctionMapping = associationSetModificationFunctionMapping; _entityContainerMapping = entityContainerMapping; }
public DynamicToFunctionModificationCommandConverter( EntityTypeModificationFunctionMapping entityTypeModificationFunctionMapping, EntityContainerMapping entityContainerMapping) { DebugCheck.NotNull(entityTypeModificationFunctionMapping); DebugCheck.NotNull(entityContainerMapping); _entityTypeModificationFunctionMapping = entityTypeModificationFunctionMapping; _entityContainerMapping = entityContainerMapping; }
private void InitializeEntitySet(EntitySetBase entitySetBase, MetadataWorkspace workspace) { EntityContainerMapping map = (EntityContainerMapping)this.m_mappingCollection.GetMap((GlobalItem)entitySetBase.EntityContainer); if (map.HasViews) { this.m_mappingCollection.GetGeneratedView(entitySetBase, workspace); } Set <EntitySet> set = new Set <EntitySet>(); if (map != null) { Set <EdmMember> columns = new Set <EdmMember>(); EntitySetBaseMapping setMapping; if (entitySetBase.BuiltInTypeKind == BuiltInTypeKind.EntitySet) { setMapping = map.GetEntitySetMapping(entitySetBase.Name); this.m_serverGenProperties.Unite(ViewLoader.GetMembersWithResultBinding((EntitySetMapping)setMapping)); } else { if (entitySetBase.BuiltInTypeKind != BuiltInTypeKind.AssociationSet) { throw new NotSupportedException(); } setMapping = map.GetAssociationSetMapping(entitySetBase.Name); } foreach (MappingFragment mappingFragment in ViewLoader.GetMappingFragments(setMapping)) { set.Add(mappingFragment.TableSet); this.m_serverGenProperties.AddRange(ViewLoader.FindServerGenMembers(mappingFragment)); columns.AddRange(ViewLoader.FindIsNullConditionColumns(mappingFragment)); } if (0 < columns.Count) { foreach (MappingFragment mappingFragment in ViewLoader.GetMappingFragments(setMapping)) { this.m_isNullConditionProperties.AddRange(ViewLoader.FindPropertiesMappedToColumns(columns, mappingFragment)); } } } this.m_affectedTables.Add(entitySetBase, set.MakeReadOnly()); this.InitializeFunctionMappingTranslators(entitySetBase, map); if (entitySetBase.BuiltInTypeKind != BuiltInTypeKind.AssociationSet) { return; } AssociationSet associationSet = (AssociationSet)entitySetBase; if (this.m_associationSetMetadata.ContainsKey(associationSet)) { return; } this.m_associationSetMetadata.Add(associationSet, new AssociationSetMetadata(this.m_affectedTables[(EntitySetBase)associationSet], associationSet, workspace)); }
private static ErrorLog EnsureAllCSpaceContainerSetsAreMapped( IEnumerable <Cell> cells, EntityContainerMapping containerMapping) { Set <EntitySetBase> set = new Set <EntitySetBase>(); EntityContainer entityContainer = (EntityContainer)null; foreach (Cell cell in cells) { set.Add(cell.CQuery.Extent); string sourceLocation = cell.CellLabel.SourceLocation; entityContainer = cell.CQuery.Extent.EntityContainer; } List <EntitySetBase> entitySetBaseList = new List <EntitySetBase>(); foreach (EntitySetBase baseEntitySet in entityContainer.BaseEntitySets) { if (!set.Contains(baseEntitySet) && !containerMapping.HasQueryViewForSetMap(baseEntitySet.Name)) { AssociationSet associationSet = baseEntitySet as AssociationSet; if (associationSet == null || !associationSet.ElementType.IsForeignKey) { entitySetBaseList.Add(baseEntitySet); } } } ErrorLog errorLog = new ErrorLog(); if (entitySetBaseList.Count > 0) { StringBuilder stringBuilder = new StringBuilder(); bool flag = true; foreach (EntitySetBase entitySetBase in entitySetBaseList) { if (!flag) { stringBuilder.Append(", "); } flag = false; stringBuilder.Append(entitySetBase.Name); } string message = Strings.ViewGen_Missing_Set_Mapping((object)stringBuilder); int num = -1; foreach (Cell cell in cells) { if (num == -1 || cell.CellLabel.StartLineNumber < num) { num = cell.CellLabel.StartLineNumber; } } ErrorLog.Record record = new ErrorLog.Record(new EdmSchemaError(message, 3027, EdmSchemaErrorSeverity.Error, containerMapping.SourceLocation, containerMapping.StartLineNumber, containerMapping.StartLinePosition, (Exception)null)); errorLog.AddEntry(record); } return(errorLog); }
/// <summary> /// Initialiazes a new EntitySetMapping instance. /// </summary> /// <param name="entitySet">The entity set to be mapped.</param> /// <param name="containerMapping">The parent container mapping.</param> public EntitySetMapping(EntitySet entitySet, EntityContainerMapping containerMapping) : base(containerMapping) { Check.NotNull(entitySet, "entitySet"); _entitySet = entitySet; _entityTypeMappings = new List<EntityTypeMapping>(); _modificationFunctionMappings = new List<EntityTypeModificationFunctionMapping>(); _implicitlyMappedAssociationSetEnds = new Lazy<List<AssociationSetEnd>>( InitializeImplicitlyMappedAssociationSetEnds); }
public void Can_retrieve_entity_container_mapping() { var model = new DbModel(new EdmModel(DataSpace.CSpace), new EdmModel(DataSpace.SSpace)); var containerMapping = new EntityContainerMapping(); Assert.Null(model.ConceptualToStoreMapping); model.DatabaseMapping.AddEntityContainerMapping(containerMapping); Assert.Same(containerMapping, model.ConceptualToStoreMapping); }
public static AssociationSetMapping AddAssociationSetMapping( this DbDatabaseMapping databaseMapping, AssociationSet associationSet, EntitySet entitySet) { EntityContainerMapping containerMapping = databaseMapping.EntityContainerMappings.Single <EntityContainerMapping>(); AssociationSetMapping setMapping = new AssociationSetMapping(associationSet, entitySet, containerMapping).Initialize(); containerMapping.AddSetMapping(setMapping); return(setMapping); }
/// <summary> /// Initializes a new AssociationSetMapping instance. /// </summary> /// <param name="associationSet">The association set to be mapped.</param> /// <param name="storeEntitySet">The store entity set to be mapped.</param> /// <param name="containerMapping">The parent container mapping.</param> public AssociationSetMapping(AssociationSet associationSet, EntitySet storeEntitySet, EntityContainerMapping containerMapping) : base(containerMapping) { Check.NotNull(associationSet, "associationSet"); Check.NotNull(storeEntitySet, "storeEntitySet"); _associationSet = associationSet; _associationTypeMapping = new AssociationTypeMapping(associationSet.ElementType, this); _associationTypeMapping.MappingFragment = new MappingFragment(storeEntitySet, _associationTypeMapping, false); }
private EntityContainer GetEntityContainer() { DbContext dbContext = dbContextFactory.CreateContext("Default" /* TODO */); //TODO: dispose or not? ObjectContext objectContext = ((IObjectContextAdapter)dbContext).ObjectContext; EntityContainerMapping containerMapping = objectContext.MetadataWorkspace .GetItem <EntityContainerMapping>(objectContext.DefaultContainerName, DataSpace.CSSpace); EntityContainer container = containerMapping.StoreEntityContainer; return(container); }
public void Can_add_container_mappings() { var mapping = new DbDatabaseMapping(); Assert.Empty(mapping.EntityContainerMappings); var containerMapping = new EntityContainerMapping(new EntityContainer()); mapping.AddEntityContainerMapping(containerMapping); Assert.Same(containerMapping, mapping.EntityContainerMappings.Single()); }
internal ViewgenContext( ViewTarget viewTarget, EntitySetBase extent, IList <Cell> extentCells, CqlIdentifiers identifiers, ConfigViewGenerator config, MemberDomainMap queryDomainMap, MemberDomainMap updateDomainMap, EntityContainerMapping entityContainerMapping) { foreach (Cell extentCell in (IEnumerable <Cell>)extentCells) { ; } this.m_extent = extent; this.m_viewTarget = viewTarget; this.m_config = config; this.m_edmItemCollection = entityContainerMapping.StorageMappingItemCollection.EdmItemCollection; this.m_entityContainerMapping = entityContainerMapping; this.m_identifiers = identifiers; updateDomainMap = updateDomainMap.MakeCopy(); MemberDomainMap domainMap = viewTarget == ViewTarget.QueryView ? queryDomainMap : updateDomainMap; this.m_memberMaps = new MemberMaps(viewTarget, MemberProjectionIndex.Create(extent, this.m_edmItemCollection), queryDomainMap, updateDomainMap); FragmentQueryKBChaseSupport kb1 = new FragmentQueryKBChaseSupport(); kb1.CreateVariableConstraints(extent, domainMap, this.m_edmItemCollection); this.m_leftFragmentQP = new FragmentQueryProcessor(kb1); this.m_rewritingCache = new Dictionary <FragmentQuery, Tile <FragmentQuery> >(FragmentQuery.GetEqualityComparer(this.m_leftFragmentQP)); if (!this.CreateLeftCellWrappers(extentCells, viewTarget)) { return; } FragmentQueryKBChaseSupport kb2 = new FragmentQueryKBChaseSupport(); MemberDomainMap memberDomainMap = viewTarget == ViewTarget.QueryView ? updateDomainMap : queryDomainMap; foreach (LeftCellWrapper cellWrapper in this.m_cellWrappers) { EntitySetBase rightExtent = cellWrapper.RightExtent; kb2.CreateVariableConstraints(rightExtent, memberDomainMap, this.m_edmItemCollection); kb2.CreateAssociationConstraints(rightExtent, memberDomainMap, this.m_edmItemCollection); } if (this.m_viewTarget == ViewTarget.UpdateView) { this.CreateConstraintsForForeignKeyAssociationsAffectingThisWrapper((FragmentQueryKB)kb2, memberDomainMap); } this.m_rightFragmentQP = new FragmentQueryProcessor(kb2); if (this.m_viewTarget == ViewTarget.QueryView) { this.CheckConcurrencyControlTokens(); } this.m_cellWrappers.Sort(LeftCellWrapper.Comparer); }
BuildEntitySetMappings(EntityContainerMapping entityContainerMapping, SimpleMappingContext mappingContext) { Debug.Assert(entityContainerMapping != null, "entityContainerMapping != null"); Debug.Assert(mappingContext != null, "mappingContext != null"); foreach (var storeEntitySet in mappingContext.StoreEntitySets()) { var entitySetMapping = new EntitySetMapping(mappingContext[storeEntitySet], entityContainerMapping); entitySetMapping.AddTypeMapping(BuildEntityTypeMapping(entitySetMapping, mappingContext, storeEntitySet)); yield return(entitySetMapping); } }
public static void BuildAssociationSetMappings_does_not_create_mappings_if_association_type_is_foreign_key() { var mappingContext = CreateSimpleMappingContext(isForeignKey: true); var storeContainer = mappingContext.StoreContainers().Single(); var modelContainer = mappingContext[storeContainer]; var entityContainerMapping = new EntityContainerMapping(modelContainer, storeContainer, null, false, false); var associationSetMappings = DbDatabaseMappingBuilder.BuildAssociationSetMappings(entityContainerMapping, mappingContext); Assert.Equal(0, associationSetMappings.Count()); }
// <summary> // Entry point for View Generation // </summary> // <returns> Generated Views for EntitySets </returns> internal static ViewGenResults GenerateViewsFromMapping(EntityContainerMapping containerMapping, ConfigViewGenerator config) { DebugCheck.NotNull(containerMapping); DebugCheck.NotNull(config); Debug.Assert(containerMapping.HasViews, "Precondition Violated: No mapping exists to generate views for!"); //Create Cells from EntityContainerMapping var cellCreator = new CellCreator(containerMapping); var cells = cellCreator.GenerateCells(); var identifiers = cellCreator.Identifiers; return(GenerateViewsFromCells(cells, config, identifiers, containerMapping)); }
/// <summary> /// Initializes a new FunctionImportMappingNonComposable instance. /// </summary> /// <param name="functionImport">The model function import.</param> /// <param name="targetFunction">The store non-composable function.</param> /// <param name="resultMappings">The function import result mappings.</param> /// <param name="containerMapping">The parent container mapping.</param> public FunctionImportMappingNonComposable( EdmFunction functionImport, EdmFunction targetFunction, IEnumerable<FunctionImportResultMapping> resultMappings, EntityContainerMapping containerMapping) : base( Check.NotNull(functionImport, "functionImport"), Check.NotNull(targetFunction, "targetFunction")) { Check.NotNull(resultMappings, "resultMappings"); Check.NotNull(containerMapping, "containerMapping"); Debug.Assert(!functionImport.IsComposableAttribute); Debug.Assert(!targetFunction.IsComposableAttribute); if (!resultMappings.Any()) { // when this method is invoked when a CodeFirst model is being built (e.g. from a custom convention) the // StorageMappingItemCollection will be null. In this case we can provide an empty EdmItemCollection which // will allow inferring implicit result mapping var edmItemCollection = containerMapping.StorageMappingItemCollection != null ? containerMapping.StorageMappingItemCollection.EdmItemCollection : new EdmItemCollection(new EdmModel(DataSpace.CSpace)); _internalResultMappings = new ReadOnlyCollection<FunctionImportStructuralTypeMappingKB>( new[] { new FunctionImportStructuralTypeMappingKB( new List<FunctionImportStructuralTypeMapping>(), edmItemCollection) }); noExplicitResultMappings = true; } else { Debug.Assert(functionImport.ReturnParameters.Count == resultMappings.Count()); _internalResultMappings = new ReadOnlyCollection<FunctionImportStructuralTypeMappingKB>( resultMappings .Select( resultMapping => new FunctionImportStructuralTypeMappingKB( resultMapping.TypeMappings, containerMapping.StorageMappingItemCollection.EdmItemCollection)) .ToArray()); noExplicitResultMappings = false; } _resultMappings = new ReadOnlyCollection<FunctionImportResultMapping>(resultMappings.ToList()); }
// effects: Creates a ViewGenerator object that is capable of // producing query or update mapping views given the relevant schema // given the "cells" internal ViewGenerator( CellGroup cellGroup, ConfigViewGenerator config, List <ForeignConstraint> foreignKeyConstraints, EntityContainerMapping entityContainerMapping) { m_cellGroup = cellGroup; m_config = config; m_queryRewriterCache = new Dictionary <EntitySetBase, QueryRewriter>(); m_foreignKeyConstraints = foreignKeyConstraints; m_entityContainerMapping = entityContainerMapping; var inheritanceGraph = MetadataHelper.BuildUndirectedGraphOfTypes(entityContainerMapping.StorageMappingItemCollection.EdmItemCollection); SetConfiguration(entityContainerMapping); // We fix all the cells at this point m_queryDomainMap = new MemberDomainMap( ViewTarget.QueryView, m_config.IsValidationEnabled, cellGroup, entityContainerMapping.StorageMappingItemCollection.EdmItemCollection, m_config, inheritanceGraph); m_updateDomainMap = new MemberDomainMap( ViewTarget.UpdateView, m_config.IsValidationEnabled, cellGroup, entityContainerMapping.StorageMappingItemCollection.EdmItemCollection, m_config, inheritanceGraph); // We now go and fix the queryDomain map so that it has all the // values from the S-side as well -- this is needed for domain // constraint propagation, i.e., values from the S-side get // propagated to te oneOfConst on the C-side. So we better get // the "possibleValues" stuff to contain those constants as well MemberDomainMap.PropagateUpdateDomainToQueryDomain(cellGroup, m_queryDomainMap, m_updateDomainMap); UpdateWhereClauseForEachCell(cellGroup, m_queryDomainMap, m_updateDomainMap, m_config); // We need to simplify cell queries, yet we don't want the conditions to disappear // So, add an extra value to the domain, temporarily var queryOpenDomain = m_queryDomainMap.GetOpenDomain(); var updateOpenDomain = m_updateDomainMap.GetOpenDomain(); // Make sure the WHERE clauses of the cells reflect the changes foreach (var cell in cellGroup) { cell.CQuery.WhereClause.FixDomainMap(queryOpenDomain); cell.SQuery.WhereClause.FixDomainMap(updateOpenDomain); cell.CQuery.WhereClause.ExpensiveSimplify(); cell.SQuery.WhereClause.ExpensiveSimplify(); cell.CQuery.WhereClause.FixDomainMap(m_queryDomainMap); cell.SQuery.WhereClause.FixDomainMap(m_updateDomainMap); } }
public void Can_get_entity_type_mappings() { var entityContainerMapping = new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)); var entitySetMapping = new EntitySetMapping(new EntitySet(), entityContainerMapping); Assert.Empty(entitySetMapping.EntityTypeMappings); var entityTypeMapping = new EntityTypeMapping( new EntitySetMapping(new EntitySet(), entityContainerMapping)); entitySetMapping.AddTypeMapping(entityTypeMapping); Assert.Same(entityTypeMapping, entitySetMapping.EntityTypeMappings.Single()); }
internal CreateAssociationSetMappingCommand( EntityContainerMapping entityContainerMapping, AssociationSet associationSet, Association association, StorageEntitySet storageEntitySet) : base(PrereqId) { CommandValidation.ValidateEntityContainerMapping(entityContainerMapping); CommandValidation.ValidateAssociationSet(associationSet); CommandValidation.ValidateAssociation(association); CommandValidation.ValidateStorageEntitySet(storageEntitySet); EntityContainerMapping = entityContainerMapping; AssociationSet = associationSet; Association = association; StorageEntitySet = storageEntitySet; }
// effects: Creates a ViewGenerator object that is capable of // producing query or update mapping views given the relevant schema // given the "cells" internal ViewGenerator( CellGroup cellGroup, ConfigViewGenerator config, List<ForeignConstraint> foreignKeyConstraints, EntityContainerMapping entityContainerMapping) { m_cellGroup = cellGroup; m_config = config; m_queryRewriterCache = new Dictionary<EntitySetBase, QueryRewriter>(); m_foreignKeyConstraints = foreignKeyConstraints; m_entityContainerMapping = entityContainerMapping; var inheritanceGraph = MetadataHelper.BuildUndirectedGraphOfTypes(entityContainerMapping.StorageMappingItemCollection.EdmItemCollection); SetConfiguration(entityContainerMapping); // We fix all the cells at this point m_queryDomainMap = new MemberDomainMap( ViewTarget.QueryView, m_config.IsValidationEnabled, cellGroup, entityContainerMapping.StorageMappingItemCollection.EdmItemCollection, m_config, inheritanceGraph); m_updateDomainMap = new MemberDomainMap( ViewTarget.UpdateView, m_config.IsValidationEnabled, cellGroup, entityContainerMapping.StorageMappingItemCollection.EdmItemCollection, m_config, inheritanceGraph); // We now go and fix the queryDomain map so that it has all the // values from the S-side as well -- this is needed for domain // constraint propagation, i.e., values from the S-side get // propagated to te oneOfConst on the C-side. So we better get // the "possiblveValues" stuff to contain those constants as well MemberDomainMap.PropagateUpdateDomainToQueryDomain(cellGroup, m_queryDomainMap, m_updateDomainMap); UpdateWhereClauseForEachCell(cellGroup, m_queryDomainMap, m_updateDomainMap, m_config); // We need to simplify cell queries, yet we don't want the conditions to disappear // So, add an extra value to the domain, temporarily var queryOpenDomain = m_queryDomainMap.GetOpenDomain(); var updateOpenDomain = m_updateDomainMap.GetOpenDomain(); // Make sure the WHERE clauses of the cells reflect the changes foreach (var cell in cellGroup) { cell.CQuery.WhereClause.FixDomainMap(queryOpenDomain); cell.SQuery.WhereClause.FixDomainMap(updateOpenDomain); cell.CQuery.WhereClause.ExpensiveSimplify(); cell.SQuery.WhereClause.ExpensiveSimplify(); cell.CQuery.WhereClause.FixDomainMap(m_queryDomainMap); cell.SQuery.WhereClause.FixDomainMap(m_updateDomainMap); } }
private void InitializeFunctionMappingTranslators( EntitySetBase entitySetBase, EntityContainerMapping mapping) { KeyToListMap <AssociationSet, AssociationEndMember> keyToListMap = new KeyToListMap <AssociationSet, AssociationEndMember>((IEqualityComparer <AssociationSet>)EqualityComparer <AssociationSet> .Default); if (!this.m_functionMappingTranslators.ContainsKey(entitySetBase)) { foreach (EntitySetMapping entitySetMap in mapping.EntitySetMaps) { if (0 < entitySetMap.ModificationFunctionMappings.Count) { this.m_functionMappingTranslators.Add(entitySetMap.Set, ModificationFunctionMappingTranslator.CreateEntitySetTranslator(entitySetMap)); foreach (AssociationSetEnd associationSetEnd in entitySetMap.ImplicitlyMappedAssociationSetEnds) { AssociationSet parentAssociationSet = associationSetEnd.ParentAssociationSet; if (!this.m_functionMappingTranslators.ContainsKey((EntitySetBase)parentAssociationSet)) { this.m_functionMappingTranslators.Add((EntitySetBase)parentAssociationSet, ModificationFunctionMappingTranslator.CreateAssociationSetTranslator((AssociationSetMapping)null)); } AssociationSetEnd oppositeEnd = MetadataHelper.GetOppositeEnd(associationSetEnd); keyToListMap.Add(parentAssociationSet, oppositeEnd.CorrespondingAssociationEndMember); } } else { this.m_functionMappingTranslators.Add(entitySetMap.Set, (ModificationFunctionMappingTranslator)null); } } foreach (AssociationSetMapping relationshipSetMap in mapping.RelationshipSetMaps) { if (relationshipSetMap.ModificationFunctionMapping != null) { AssociationSet set = (AssociationSet)relationshipSetMap.Set; this.m_functionMappingTranslators.Add((EntitySetBase)set, ModificationFunctionMappingTranslator.CreateAssociationSetTranslator(relationshipSetMap)); keyToListMap.AddRange(set, Enumerable.Empty <AssociationEndMember>()); } else if (!this.m_functionMappingTranslators.ContainsKey(relationshipSetMap.Set)) { this.m_functionMappingTranslators.Add(relationshipSetMap.Set, (ModificationFunctionMappingTranslator)null); } } } foreach (AssociationSet key in keyToListMap.Keys) { this.m_associationSetMetadata.Add(key, new AssociationSetMetadata(keyToListMap.EnumerateValues(key))); } }
protected override void InvokeInternal(CommandProcessorContext cpc) { if (_artifact == null) { throw new InvalidOperationException("InvokeInternal is called when _artifact is null"); } var ecm = new EntityContainerMapping(_artifact.MappingModel(), null); ecm.CdmEntityContainer.SetRefName(_artifact.ConceptualModel().FirstEntityContainer); ecm.StorageEntityContainer.SetRefName(_artifact.StorageModel().FirstEntityContainer); _artifact.MappingModel().AddEntityContainerMapping(ecm); XmlModelHelper.NormalizeAndResolve(ecm); _created = ecm; }
public void Can_get_association_set_mappings() { var entityContainerMapping = new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)); Assert.Empty(entityContainerMapping.AssociationSetMappings); Assert.Empty(entityContainerMapping.RelationshipSetMaps); var associationSetMapping = new AssociationSetMapping( new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)), entityContainerMapping); entityContainerMapping.AddSetMapping(associationSetMapping); Assert.Same(associationSetMapping, entityContainerMapping.AssociationSetMappings.Single()); Assert.Same(associationSetMapping, entityContainerMapping.RelationshipSetMaps.Single()); }
public void Can_get_entity_set_mappings() { var entityContainerMapping = new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)); Assert.Empty(entityContainerMapping.EntitySetMappings); Assert.Empty(entityContainerMapping.EntitySetMaps); var entitySetMapping = new EntitySetMapping( new EntitySet("ES", null, null, null, new EntityType("E", "N", DataSpace.CSpace)), entityContainerMapping); entityContainerMapping.AddSetMapping(entitySetMapping); Assert.Same(entitySetMapping, entityContainerMapping.EntitySetMappings.Single()); Assert.Same(entitySetMapping, entityContainerMapping.EntitySetMaps.Single()); }
internal static IEnumerable <TypeMapping> GetMappingsForEntitySetAndType( StorageMappingItemCollection mappingCollection, EntityContainer container, EntitySetBase entitySet, EntityTypeBase entityType) { EntityContainerMapping containerMapping = MappingMetadataHelper.GetEntityContainerMap(mappingCollection, container); EntitySetBaseMapping extentMap = containerMapping.GetSetMapping(entitySet.Name); if (extentMap != null) { foreach (TypeMapping typeMapping in extentMap.TypeMappings.Where <TypeMapping>((Func <TypeMapping, bool>)(map => map.Types.Union <EntityTypeBase>((IEnumerable <EntityTypeBase>)map.IsOfTypes).Contains <EntityTypeBase>(entityType)))) { yield return(typeMapping); } } }
public override void Parse(XmlNode dom) { this.Space = dom.Attributes["Space"].Value; this.XmlNs = dom.Attributes["xmlns"].Value; foreach (XmlNode n in dom.ChildNodes) { if (n.Name == "EntityContainerMapping") { var mapping = new EntityContainerMapping(); mapping.Parse(n); mapping.Parent = this; EntityContainerMapping = mapping; } } base.Parse(dom); }
private static AssociationSetMapping BuildAssociationSetMapping( AssociationSet storeAssociationSet, EntityContainerMapping entityContainerMapping, SimpleMappingContext mappingContext) { Debug.Assert(storeAssociationSet != null, "storeAssociationSet != null"); Debug.Assert(entityContainerMapping != null, "entityContainerMapping != null"); Debug.Assert(mappingContext != null, "mappingContext != null"); var modelAssociationSet = mappingContext[storeAssociationSet]; if (modelAssociationSet.ElementType.IsForeignKey) { return(null); } var foreignKeyTableEnd = GetAssociationSetEndForForeignKeyTable(storeAssociationSet); var associationSetMapping = new AssociationSetMapping( modelAssociationSet, foreignKeyTableEnd.EntitySet, entityContainerMapping); var count = storeAssociationSet.AssociationSetEnds.Count; if (count > 0) { associationSetMapping.SourceEndMapping = BuildEndPropertyMapping( storeAssociationSet.AssociationSetEnds[0], mappingContext); } if (count > 1) { associationSetMapping.TargetEndMapping = BuildEndPropertyMapping( storeAssociationSet.AssociationSetEnds[1], mappingContext); } var constraint = GetReferentialConstraint(storeAssociationSet); foreach (var foreignKeyColumn in constraint.ToProperties) { if (foreignKeyColumn.Nullable) { associationSetMapping.AddCondition( new IsNullConditionMapping(foreignKeyColumn, false)); } } return(associationSetMapping); }
internal static IEnumerable <EntityTypeModificationFunctionMapping> GetModificationFunctionMappingsForEntitySetAndType( StorageMappingItemCollection mappingCollection, EntityContainer container, EntitySetBase entitySet, EntityTypeBase entityType) { EntityContainerMapping containerMapping = MappingMetadataHelper.GetEntityContainerMap(mappingCollection, container); EntitySetBaseMapping extentMap = containerMapping.GetSetMapping(entitySet.Name); EntitySetMapping entitySetMapping = extentMap as EntitySetMapping; if (entitySetMapping != null && entitySetMapping != null) { foreach (EntityTypeModificationFunctionMapping modificationFunctionMapping in entitySetMapping.ModificationFunctionMappings.Where <EntityTypeModificationFunctionMapping>((Func <EntityTypeModificationFunctionMapping, bool>)(functionMap => functionMap.EntityType.Equals((object)entityType)))) { yield return(modificationFunctionMapping); } } }
private static ViewGenResults GenerateViewsFromCells( List <Cell> cells, ConfigViewGenerator config, CqlIdentifiers identifiers, EntityContainerMapping containerMapping) { EntityContainer storageEntityContainer = containerMapping.StorageEntityContainer; ViewGenResults viewGenResults = new ViewGenResults(); ErrorLog errorLog1 = ViewgenGatekeeper.EnsureAllCSpaceContainerSetsAreMapped((IEnumerable <Cell>)cells, containerMapping); if (errorLog1.Count > 0) { viewGenResults.AddErrors(errorLog1); Helpers.StringTraceLine(viewGenResults.ErrorsToString()); return(viewGenResults); } List <ForeignConstraint> foreignConstraints = ForeignConstraint.GetForeignConstraints(storageEntityContainer); foreach (Set <Cell> groupRelatedCell in new CellPartitioner((IEnumerable <Cell>)cells, (IEnumerable <ForeignConstraint>)foreignConstraints).GroupRelatedCells()) { ViewGenerator viewGenerator = (ViewGenerator)null; ErrorLog errorLog2 = new ErrorLog(); try { viewGenerator = new ViewGenerator(groupRelatedCell, config, foreignConstraints, containerMapping); } catch (InternalMappingException ex) { errorLog2 = ex.ErrorLog; } if (errorLog2.Count == 0) { errorLog2 = viewGenerator.GenerateAllBidirectionalViews(viewGenResults.Views, identifiers); } if (errorLog2.Count != 0) { viewGenResults.AddErrors(errorLog2); } } return(viewGenResults); }
protected override void Visit(EntityContainerMapping entityContainerMapping) { DebugCheck.NotNull(entityContainerMapping); // at the entry point of visitor, we setup the versions Debug.Assert( m_MappingVersion == entityContainerMapping.StorageMappingItemCollection.MappingVersion, "the original version and the mapping collection version are not the same"); m_MappingVersion = entityContainerMapping.StorageMappingItemCollection.MappingVersion; m_EdmItemCollection = entityContainerMapping.StorageMappingItemCollection.EdmItemCollection; int index; if (!AddObjectToSeenListAndHashBuilder(entityContainerMapping, out index)) { // if this has been add to the seen list, then just return; } if (m_itemsAlreadySeen.Count > 1) { // this means user try another visit over SECM, this is allowed but all the previous visit all lost due to clean // user can visit different SECM objects by using the same visitor to load the SECM object Clean(); Visit(entityContainerMapping); return; } AddObjectStartDumpToHashBuilder(entityContainerMapping, index); #region Inner data visit AddObjectContentToHashBuilder(entityContainerMapping.Identity); AddV2ObjectContentToHashBuilder(entityContainerMapping.GenerateUpdateViews, m_MappingVersion); base.Visit(entityContainerMapping); #endregion AddObjectEndDumpToHashBuilder(); }
internal static EntityContainerMapping GetEntityContainerMap( StorageMappingItemCollection mappingCollection, EntityContainer entityContainer) { var entityContainerMaps = mappingCollection.GetItems <EntityContainerMapping>(); EntityContainerMapping entityContainerMap = null; foreach (var map in entityContainerMaps) { if ((entityContainer.Equals(map.EdmEntityContainer)) || (entityContainer.Equals(map.StorageEntityContainer))) { entityContainerMap = map; break; } } if (entityContainerMap == null) { throw new MappingException(Strings.Mapping_NotFound_EntityContainer(entityContainer.Name)); } return(entityContainerMap); }
internal static EntityContainerMapping GetEntityContainerMap( StorageMappingItemCollection mappingCollection, EntityContainer entityContainer) { ReadOnlyCollection <EntityContainerMapping> items = mappingCollection.GetItems <EntityContainerMapping>(); EntityContainerMapping containerMapping1 = (EntityContainerMapping)null; foreach (EntityContainerMapping containerMapping2 in items) { if (entityContainer.Equals((object)containerMapping2.EdmEntityContainer) || entityContainer.Equals((object)containerMapping2.StorageEntityContainer)) { containerMapping1 = containerMapping2; break; } } if (containerMapping1 == null) { throw new MappingException(Strings.Mapping_NotFound_EntityContainer((object)entityContainer.Name)); } return(containerMapping1); }
protected override void InvokeInternal(CommandProcessorContext cpc) { // if we don't have an ECM yet, go create one if (EntityContainerMapping == null) { var createECM = new CreateEntityContainerMappingCommand(AssociationSet.Artifact); CommandProcessor.InvokeSingleCommand(cpc, createECM); EntityContainerMapping = createECM.EntityContainerMapping; } Debug.Assert(EntityContainerMapping != null, "EntityContainerMapping should not be null"); if (EntityContainerMapping == null) { throw new CannotLocateParentItemException(); } // create the ETM var asm = new AssociationSetMapping(EntityContainerMapping, null); asm.Name.SetRefName(AssociationSet); asm.TypeName.SetRefName(Association); asm.StoreEntitySet.SetRefName(StorageEntitySet); EntityContainerMapping.AddAssociationSetMapping(asm); XmlModelHelper.NormalizeAndResolve(asm); Debug.Assert(asm.Name.Target != null, "Could not resolve association set reference"); Debug.Assert(asm.TypeName.Target != null, "Could not resolve association type reference"); Debug.Assert(asm.StoreEntitySet.Target != null, "Could not resolve table reference"); var assoc = asm.TypeName.Target; Debug.Assert(assoc != null, "Could not resolve association reference"); if (assoc != null) { InferReferentialConstraints.AddRule(cpc, assoc); } _created = asm; }
internal void WriteEntityContainerMappingElement(EntityContainerMapping containerMapping) { this._xmlWriter.WriteStartElement("EntityContainerMapping"); this._xmlWriter.WriteAttributeString("StorageEntityContainer", this._dbSchemaName); this._xmlWriter.WriteAttributeString("CdmEntityContainer", containerMapping.EdmEntityContainer.Name); foreach (EntitySetMapping entitySetMapping in containerMapping.EntitySetMappings) { this.WriteEntitySetMappingElement(entitySetMapping); } foreach (AssociationSetMapping associationSetMapping in containerMapping.AssociationSetMappings) { this.WriteAssociationSetMappingElement(associationSetMapping); } foreach (FunctionImportMappingComposable functionImportMapping in containerMapping.FunctionImportMappings.OfType <FunctionImportMappingComposable>()) { this.WriteFunctionImportMappingElement(functionImportMapping); } foreach (FunctionImportMappingNonComposable functionImportMapping in containerMapping.FunctionImportMappings.OfType <FunctionImportMappingNonComposable>()) { this.WriteFunctionImportMappingElement(functionImportMapping); } this._xmlWriter.WriteEndElement(); }
private void SetConfiguration(EntityContainerMapping entityContainerMapping) { m_config.IsValidationEnabled = entityContainerMapping.Validate; m_config.GenerateUpdateViews = entityContainerMapping.GenerateUpdateViews; }
private void RecordEntityTypeIdentities( EntityContainerMapping entityContainerMapping) { // construct mapping from EntityType to EntityTypeIdentity which // is its identity UpdateModelFromDatabaseUtils.ConstructEntityMappings( entityContainerMapping, AddCEntityTypeNameToEntityTypeIdentityMapping); }
internal ViewgenContext( ViewTarget viewTarget, EntitySetBase extent, IList <Cell> extentCells, CqlIdentifiers identifiers, ConfigViewGenerator config, MemberDomainMap queryDomainMap, MemberDomainMap updateDomainMap, EntityContainerMapping entityContainerMapping) { foreach (var cell in extentCells) { Debug.Assert(extent.Equals(cell.GetLeftQuery(viewTarget).Extent)); Debug.Assert(cell.CQuery.NumProjectedSlots == cell.SQuery.NumProjectedSlots); } m_extent = extent; m_viewTarget = viewTarget; m_config = config; m_edmItemCollection = entityContainerMapping.StorageMappingItemCollection.EdmItemCollection; m_entityContainerMapping = entityContainerMapping; m_identifiers = identifiers; // create a copy of updateDomainMap so generation of query views later on is not affected // it is modified in QueryRewriter.AdjustMemberDomainsForUpdateViews updateDomainMap = updateDomainMap.MakeCopy(); // Create a signature generator that handles all the // multiconstant work and generating the signatures var domainMap = viewTarget == ViewTarget.QueryView ? queryDomainMap : updateDomainMap; m_memberMaps = new MemberMaps( viewTarget, MemberProjectionIndex.Create(extent, m_edmItemCollection), queryDomainMap, updateDomainMap); // Create left fragment KB: includes constraints for the extent to be constructed var leftKB = new FragmentQueryKBChaseSupport(); leftKB.CreateVariableConstraints(extent, domainMap, m_edmItemCollection); m_leftFragmentQP = new FragmentQueryProcessor(leftKB); m_rewritingCache = new Dictionary <FragmentQuery, Tile <FragmentQuery> >( FragmentQuery.GetEqualityComparer(m_leftFragmentQP)); // Now using the signatures, create new cells such that // "extent's" query (C or S) is described in terms of multiconstants if (!CreateLeftCellWrappers(extentCells, viewTarget)) { return; } // Create right fragment KB: includes constraints for all extents and association roles of right queries var rightKB = new FragmentQueryKBChaseSupport(); var rightDomainMap = viewTarget == ViewTarget.QueryView ? updateDomainMap : queryDomainMap; foreach (var leftCellWrapper in m_cellWrappers) { var rightExtent = leftCellWrapper.RightExtent; rightKB.CreateVariableConstraints(rightExtent, rightDomainMap, m_edmItemCollection); rightKB.CreateAssociationConstraints(rightExtent, rightDomainMap, m_edmItemCollection); } if (m_viewTarget == ViewTarget.UpdateView) { CreateConstraintsForForeignKeyAssociationsAffectingThisWrapper(rightKB, rightDomainMap); } m_rightFragmentQP = new FragmentQueryProcessor(rightKB); // Check for concurrency control tokens if (m_viewTarget == ViewTarget.QueryView) { CheckConcurrencyControlTokens(); } // For backward compatibility - // order wrappers by increasing domain size, decreasing number of attributes m_cellWrappers.Sort(LeftCellWrapper.Comparer); }
// Loads and registers any function mapping translators for the given extent (and related container) private void InitializeFunctionMappingTranslators(EntitySetBase entitySetBase, EntityContainerMapping mapping) { var requiredEnds = new KeyToListMap <AssociationSet, AssociationEndMember>( EqualityComparer <AssociationSet> .Default); // see if function mapping metadata needs to be processed if (!m_functionMappingTranslators.ContainsKey(entitySetBase)) { // load all function mapping data from the current entity container foreach (EntitySetMapping entitySetMapping in mapping.EntitySetMaps) { if (0 < entitySetMapping.ModificationFunctionMappings.Count) { // register the function mapping m_functionMappingTranslators.Add( entitySetMapping.Set, ModificationFunctionMappingTranslator.CreateEntitySetTranslator(entitySetMapping)); // register "null" function translators for all implicitly mapped association sets foreach (var end in entitySetMapping.ImplicitlyMappedAssociationSetEnds) { var associationSet = end.ParentAssociationSet; if (!m_functionMappingTranslators.ContainsKey(associationSet)) { m_functionMappingTranslators.Add( associationSet, ModificationFunctionMappingTranslator.CreateAssociationSetTranslator(null)); } // Remember that the current entity set is required for all updates to the collocated // relationship set. This entity set's end is opposite the target end for the mapping. var oppositeEnd = MetadataHelper.GetOppositeEnd(end); requiredEnds.Add(associationSet, oppositeEnd.CorrespondingAssociationEndMember); } } else { // register null translator (so that we never attempt to process this extent again) m_functionMappingTranslators.Add(entitySetMapping.Set, null); } } foreach (AssociationSetMapping associationSetMapping in mapping.RelationshipSetMaps) { if (null != associationSetMapping.ModificationFunctionMapping) { var set = (AssociationSet)associationSetMapping.Set; // use indexer rather than Add since the association set may already have an implicit function // mapping -- this explicit function mapping takes precedence in such cases m_functionMappingTranslators.Add( set, ModificationFunctionMappingTranslator.CreateAssociationSetTranslator(associationSetMapping)); // remember that we've seen a function mapping for this association set, which overrides // any other behaviors for determining required/optional ends requiredEnds.AddRange(set, Enumerable.Empty <AssociationEndMember>()); } else { if (!m_functionMappingTranslators.ContainsKey(associationSetMapping.Set)) { // register null translator (so that we never attempt to process this extent again) m_functionMappingTranslators.Add(associationSetMapping.Set, null); } } } } // register association metadata for all association sets encountered foreach (var associationSet in requiredEnds.Keys) { m_associationSetMetadata.Add( associationSet, new AssociationSetMetadata( requiredEnds.EnumerateValues(associationSet))); } }
private void SerializedCollectViewsFromCache( EntityContainerMapping containerMapping, Dictionary<EntitySetBase, GeneratedView> extentMappingViews) { var mappingViewCacheFactory = _storageMappingItemCollection.MappingViewCacheFactory; DebugCheck.NotNull(mappingViewCacheFactory); var mappingViewCache = mappingViewCacheFactory.Create(containerMapping); if (mappingViewCache == null) { return; } var mappingHashValue = MetadataMappingHasherVisitor.GetMappingClosureHash( containerMapping.StorageMappingItemCollection.MappingVersion, containerMapping); if (mappingHashValue != mappingViewCache.MappingHashValue) { throw new MappingException( Strings.ViewGen_HashOnMappingClosure_Not_Matching( mappingViewCache.GetType().Name)); } foreach (var extent in containerMapping.StorageEntityContainer.BaseEntitySets.Union( containerMapping.EdmEntityContainer.BaseEntitySets)) { GeneratedView generatedView; if (extentMappingViews.TryGetValue(extent, out generatedView)) { continue; } var mappingView = mappingViewCache.GetView(extent); if (mappingView == null) { continue; } generatedView = GeneratedView.CreateGeneratedView( extent, null, // edmType null, // commandTree mappingView.EntitySql, // eSQL _storageMappingItemCollection, new ConfigViewGenerator()); extentMappingViews.Add(extent, generatedView); } }
internal static Dictionary<EntitySetBase, DbMappingView> GenerateViews( EntityContainerMapping containerMapping, IList<EdmSchemaError> errors) { var views = new Dictionary<EntitySetBase, DbMappingView>(); if (!containerMapping.HasViews) { return views; } // If the entity container mapping has only query views, add a warning and return. if (!containerMapping.HasMappingFragments()) { Debug.Assert( 2088 == (int)MappingErrorCode.MappingAllQueryViewAtCompileTime, "Please change the ERRORCODE_MAPPINGALLQUERYVIEWATCOMPILETIME value as well."); errors.Add( new EdmSchemaError( Strings.Mapping_AllQueryViewAtCompileTime(containerMapping.Identity), (int)MappingErrorCode.MappingAllQueryViewAtCompileTime, EdmSchemaErrorSeverity.Warning)); return views; } var viewGenResults = ViewgenGatekeeper.GenerateViewsFromMapping( containerMapping, new ConfigViewGenerator { GenerateEsql = true }); if (viewGenResults.HasErrors) { viewGenResults.Errors.Each(e => errors.Add(e)); } foreach (var extentViewPair in viewGenResults.Views.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. views.Add(extentViewPair.Key, new DbMappingView(extentViewPair.Value[0].eSQL)); } return views; }
// <summary> // Call the View Generator's Generate view method // and collect the Views and store it in a local dictionary. // </summary> private static void SerializedGenerateViews( EntityContainerMapping entityContainerMap, Dictionary<EntitySetBase, GeneratedView> resultDictionary) { //If there are no entity set maps, don't call the view generation process Debug.Assert(entityContainerMap.HasViews); var viewGenResults = ViewgenGatekeeper.GenerateViewsFromMapping(entityContainerMap, _config); var extentMappingViews = viewGenResults.Views; if (viewGenResults.HasErrors) { // Can get the list of errors using viewGenResults.Errors throw new MappingException(Helper.CombineErrorMessage(viewGenResults.Errors)); } foreach (var 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); } } }
// effects: Creates a cell creator object for an entity container's // mappings (specified in "maps") internal CellCreator(EntityContainerMapping containerMapping) { m_containerMapping = containerMapping; m_identifiers = new CqlIdentifiers(); }
// <summary> // This method compiles all the user defined query views in the <paramref name="entityContainerMapping" />. // </summary> private static void CompileUserDefinedQueryViews( EntityContainerMapping entityContainerMapping, Dictionary<EntitySetBase, GeneratedView> userDefinedQueryViewsDict, Dictionary<OfTypeQVCacheKey, GeneratedView> userDefinedQueryViewsOfTypeDict, IList<EdmSchemaError> errors) { var config = new ConfigViewGenerator(); foreach (var setMapping in entityContainerMapping.AllSetMaps) { if (setMapping.QueryView != null) { GeneratedView generatedView; if (!userDefinedQueryViewsDict.TryGetValue(setMapping.Set, out generatedView)) { // Parse the view so that we will get back any errors in the view. if (GeneratedView.TryParseUserSpecifiedView( setMapping, setMapping.Set.ElementType, setMapping.QueryView, true, // includeSubtypes entityContainerMapping.StorageMappingItemCollection, config, /*out*/ errors, out generatedView)) { // Add first QueryView userDefinedQueryViewsDict.Add(setMapping.Set, generatedView); } // Add all type-specific QueryViews foreach (var key in setMapping.GetTypeSpecificQVKeys()) { Debug.Assert(key.First.Equals(setMapping.Set)); if (GeneratedView.TryParseUserSpecifiedView( setMapping, key.Second.First, // type setMapping.GetTypeSpecificQueryView(key), key.Second.Second, // includeSubtypes entityContainerMapping.StorageMappingItemCollection, config, /*out*/ errors, out generatedView)) { userDefinedQueryViewsOfTypeDict.Add(key, generatedView); } } } } } }