private static IEnumerable <MappingFragment> GetMappingFragments( EntitySetBaseMapping setMapping) { foreach (TypeMapping typeMapping in setMapping.TypeMappings) { foreach (MappingFragment mappingFragment in typeMapping.MappingFragments) { yield return(mappingFragment); } } }
// <summary> // Enumerates all mapping fragments in given set mapping. // </summary> private static IEnumerable <MappingFragment> GetMappingFragments(EntitySetBaseMapping setMapping) { // get all type mappings for the extent foreach (var typeMapping in setMapping.TypeMappings) { // get all table mapping fragments for the type foreach (var mappingFragment in typeMapping.MappingFragments) { yield return(mappingFragment); } } }
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); } } }
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); } } }
internal static bool TryParseUserSpecifiedView( EntitySetBaseMapping setMapping, EntityTypeBase type, string eSQL, bool includeSubtypes, StorageMappingItemCollection mappingItemCollection, ConfigViewGenerator config, IList <EdmSchemaError> errors, out GeneratedView generatedView) { bool flag = false; DbQueryCommandTree commandTree; DiscriminatorMap discriminatorMap; Exception parserException; if (!GeneratedView.TryParseView(eSQL, true, setMapping.Set, mappingItemCollection, config, out commandTree, out discriminatorMap, out parserException)) { EdmSchemaError edmSchemaError = new EdmSchemaError(Strings.Mapping_Invalid_QueryView2((object)setMapping.Set.Name, (object)parserException.Message), 2068, EdmSchemaErrorSeverity.Error, setMapping.EntityContainerMapping.SourceLocation, setMapping.StartLineNumber, setMapping.StartLinePosition, parserException); errors.Add(edmSchemaError); flag = true; } else { foreach (EdmSchemaError edmSchemaError in ViewValidator.ValidateQueryView(commandTree, setMapping, type, includeSubtypes)) { errors.Add(edmSchemaError); flag = true; } CollectionType edmType = commandTree.Query.ResultType.EdmType as CollectionType; if (edmType == null || !setMapping.Set.ElementType.IsAssignableFrom(edmType.TypeUsage.EdmType)) { EdmSchemaError edmSchemaError = new EdmSchemaError(Strings.Mapping_Invalid_QueryView_Type((object)setMapping.Set.Name), 2069, EdmSchemaErrorSeverity.Error, setMapping.EntityContainerMapping.SourceLocation, setMapping.StartLineNumber, setMapping.StartLinePosition); errors.Add(edmSchemaError); flag = true; } } if (!flag) { generatedView = new GeneratedView(setMapping.Set, (EdmType)type, commandTree, eSQL, discriminatorMap, mappingItemCollection, config); return(true); } generatedView = (GeneratedView)null; return(false); }
// <summary> // Creates generated view object for the combination of the <paramref name="setMapping" />.Set and the // <paramref // name="type" /> // . // This constructor is used for user-defined query views only. // </summary> internal static bool TryParseUserSpecifiedView( EntitySetBaseMapping setMapping, EntityTypeBase type, string eSQL, bool includeSubtypes, StorageMappingItemCollection mappingItemCollection, ConfigViewGenerator config, /*out*/ IList <EdmSchemaError> errors, out GeneratedView generatedView) { var failed = false; DbQueryCommandTree commandTree; DiscriminatorMap discriminatorMap; Exception parserException; if ( !TryParseView( eSQL, true, setMapping.Set, mappingItemCollection, config, out commandTree, out discriminatorMap, out parserException)) { var error = new EdmSchemaError( Strings.Mapping_Invalid_QueryView2(setMapping.Set.Name, parserException.Message), (int)MappingErrorCode.InvalidQueryView, EdmSchemaErrorSeverity.Error, setMapping.EntityContainerMapping.SourceLocation, setMapping.StartLineNumber, setMapping.StartLinePosition, parserException); errors.Add(error); failed = true; } else { Debug.Assert(commandTree != null, "commandTree not set after parsing the view"); // Verify that all expressions appearing in the view are supported. foreach (var error in ViewValidator.ValidateQueryView(commandTree, setMapping, type, includeSubtypes)) { errors.Add(error); failed = true; } // Verify that the result type of the query view is assignable to the element type of the entityset var queryResultType = (commandTree.Query.ResultType.EdmType) as CollectionType; if ((queryResultType == null) || (!setMapping.Set.ElementType.IsAssignableFrom(queryResultType.TypeUsage.EdmType))) { var error = new EdmSchemaError( Strings.Mapping_Invalid_QueryView_Type(setMapping.Set.Name), (int)MappingErrorCode.InvalidQueryViewResultType, EdmSchemaErrorSeverity.Error, setMapping.EntityContainerMapping.SourceLocation, setMapping.StartLineNumber, setMapping.StartLinePosition); errors.Add(error); failed = true; } } if (!failed) { generatedView = new GeneratedView(setMapping.Set, type, commandTree, eSQL, discriminatorMap, mappingItemCollection, config); return(true); } else { generatedView = null; return(false); } }
// <summary> // Creates generated view object for the combination of the <paramref name="setMapping" />.Set and the // <paramref // name="type" /> // . // This constructor is used for user-defined query views only. // </summary> internal static bool TryParseUserSpecifiedView( EntitySetBaseMapping setMapping, EntityTypeBase type, string eSQL, bool includeSubtypes, StorageMappingItemCollection mappingItemCollection, ConfigViewGenerator config, /*out*/ IList<EdmSchemaError> errors, out GeneratedView generatedView) { var failed = false; DbQueryCommandTree commandTree; DiscriminatorMap discriminatorMap; Exception parserException; if ( !TryParseView( eSQL, true, setMapping.Set, mappingItemCollection, config, out commandTree, out discriminatorMap, out parserException)) { var error = new EdmSchemaError( Strings.Mapping_Invalid_QueryView2(setMapping.Set.Name, parserException.Message), (int)MappingErrorCode.InvalidQueryView, EdmSchemaErrorSeverity.Error, setMapping.EntityContainerMapping.SourceLocation, setMapping.StartLineNumber, setMapping.StartLinePosition, parserException); errors.Add(error); failed = true; } else { Debug.Assert(commandTree != null, "commandTree not set after parsing the view"); // Verify that all expressions appearing in the view are supported. foreach (var error in ViewValidator.ValidateQueryView(commandTree, setMapping, type, includeSubtypes)) { errors.Add(error); failed = true; } // Verify that the result type of the query view is assignable to the element type of the entityset var queryResultType = (commandTree.Query.ResultType.EdmType) as CollectionType; if ((queryResultType == null) || (!setMapping.Set.ElementType.IsAssignableFrom(queryResultType.TypeUsage.EdmType))) { var error = new EdmSchemaError( Strings.Mapping_Invalid_QueryView_Type(setMapping.Set.Name), (int)MappingErrorCode.InvalidQueryViewResultType, EdmSchemaErrorSeverity.Error, setMapping.EntityContainerMapping.SourceLocation, setMapping.StartLineNumber, setMapping.StartLinePosition); errors.Add(error); failed = true; } } if (!failed) { generatedView = new GeneratedView(setMapping.Set, type, commandTree, eSQL, discriminatorMap, mappingItemCollection, config); return true; } else { generatedView = null; return false; } }