/// <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(StorageSetMapping setMapping, EntityTypeBase type, string eSQL, bool includeSubtypes, StorageMappingItemCollection mappingItemCollection, ConfigViewGenerator config, /*out*/ IList <EdmSchemaError> errors, out GeneratedView generatedView) { bool failed = false; DbQueryCommandTree commandTree; DiscriminatorMap discriminatorMap; Exception parserException; if (!GeneratedView.TryParseView(eSQL, true, setMapping.Set, mappingItemCollection, config, out commandTree, out discriminatorMap, out parserException)) { EdmSchemaError error = new EdmSchemaError(System.Data.Entity.Strings.Mapping_Invalid_QueryView2(setMapping.Set.Name, parserException.Message), (int)StorageMappingErrorCode.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 CollectionType queryResultType = (commandTree.Query.ResultType.EdmType) as CollectionType; if ((queryResultType == null) || (!setMapping.Set.ElementType.IsAssignableFrom(queryResultType.TypeUsage.EdmType))) { EdmSchemaError error = new EdmSchemaError(System.Data.Entity.Strings.Mapping_Invalid_QueryView_Type(setMapping.Set.Name), (int)StorageMappingErrorCode.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> /// Performs schema validation/modification to match the type /// </summary> /// <param name="typeInfo"></param> public virtual void ValidateType(DatabaseTypeInfo typeInfo) { if (!typeInfo.BypassValidation) { if (typeInfo.IsView) { ViewValidator.ValidateObject(typeInfo); } else { TableValidator.ValidateObject(typeInfo); } } }
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); }
private bool CanSave(object sender) { return(ViewValidator.IsValid(sender as DependencyObject)); }