public void CollectStoreModelErrors_returns_errors_on_model_items() { var edmSchemaError = new EdmSchemaError("msg", 42, EdmSchemaErrorSeverity.Error); var errorMetadataProperty = MetadataProperty.Create( MetadataItemHelper.SchemaErrorsMetadataPropertyName, TypeUsage.CreateDefaultTypeUsage( PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String).GetCollectionType()), new List <EdmSchemaError> { edmSchemaError }); var entityType = EntityType.Create( "foo", "bar", DataSpace.SSpace, new string[0], new EdmMember[0], new[] { errorMetadataProperty }); var model = new EdmModel(DataSpace.SSpace); model.AddItem(entityType); var schemaErrors = ModelGenerator.CollectStoreModelErrors(model); Assert.NotNull(schemaErrors); Assert.Equal(1, schemaErrors.Count); Assert.Same(edmSchemaError, schemaErrors.Single()); }
public void ValidateArtifactSet_returns_errors_cached_when_reverse_engineering_db() { SetupModelAndInvokeAction( "<Schema xmlns=\"http://schemas.microsoft.com/ado/2009/11/edm\" Namespace=\"Model\">" + " <EntityContainer Name=\"ModelContainer\" />" + "</Schema>", "<Schema xmlns=\"http://schemas.microsoft.com/ado/2009/11/edm/ssdl\" Namespace=\"Model.Store\" Provider=\"System.Data.SqlClient\" ProviderManifestToken=\"2012\">" + " <EntityContainer Name=\"StoreContainer\" />" + "</Schema>", "<Mapping Space=\"C-S\" xmlns=\"http://schemas.microsoft.com/ado/2009/11/mapping/cs\">" + " <EntityContainerMapping StorageEntityContainer=\"StoreContainer\" CdmEntityContainer=\"ModelContainer\" />" + "</Mapping>", (mockModelManager, mockArtifactSet) => { var error = new EdmSchemaError("test", 42, EdmSchemaErrorSeverity.Error); var artifactSet = mockArtifactSet.Object; var mockArtifact = Mock.Get(artifactSet.GetEntityDesignArtifact()); mockArtifact .Setup(m => m.GetModelGenErrors()) .Returns(new List <EdmSchemaError>(new[] { error })); new RuntimeMetadataValidator(mockModelManager.Object, new Version(3, 0, 0, 0), _resolver) .ValidateArtifactSet(artifactSet, forceValidation: true, validateMsl: true, runViewGen: true); var errors = artifactSet.GetAllErrors(); Assert.Equal(1, errors.Count); Assert.Equal(1, errors.Count(e => e.ErrorClass == ErrorClass.Runtime_SSDL)); Assert.Contains(error.Message, errors.Single().Message); mockArtifactSet.Verify(m => m.AddError(It.IsAny <ErrorInfo>()), Times.Exactly(1)); }); }
internal bool ValidateTypeConditions( bool validateAmbiguity, IList <EdmSchemaError> errors, string sourceLocation) { KeyToListMap <EntityType, LineInfo> unreachableEntityTypes; KeyToListMap <EntityType, LineInfo> unreachableIsTypeOfs; this.GetUnreachableTypes(validateAmbiguity, out unreachableEntityTypes, out unreachableIsTypeOfs); bool flag = true; foreach (KeyValuePair <EntityType, List <LineInfo> > keyValuePair in unreachableEntityTypes.KeyValuePairs) { LineInfo lineInfo = keyValuePair.Value.First <LineInfo>(); string commaSeparatedString = StringUtil.ToCommaSeparatedString((IEnumerable)keyValuePair.Value.Select <LineInfo, int>((Func <LineInfo, int>)(li => li.LineNumber))); EdmSchemaError edmSchemaError = new EdmSchemaError(Strings.Mapping_FunctionImport_UnreachableType((object)keyValuePair.Key.FullName, (object)commaSeparatedString), 2076, EdmSchemaErrorSeverity.Error, sourceLocation, lineInfo.LineNumber, lineInfo.LinePosition); errors.Add(edmSchemaError); flag = false; } foreach (KeyValuePair <EntityType, List <LineInfo> > keyValuePair in unreachableIsTypeOfs.KeyValuePairs) { LineInfo lineInfo = keyValuePair.Value.First <LineInfo>(); string commaSeparatedString = StringUtil.ToCommaSeparatedString((IEnumerable)keyValuePair.Value.Select <LineInfo, int>((Func <LineInfo, int>)(li => li.LineNumber))); EdmSchemaError edmSchemaError = new EdmSchemaError(Strings.Mapping_FunctionImport_UnreachableIsTypeOf((object)("IsTypeOf(" + keyValuePair.Key.FullName + ")"), (object)commaSeparatedString), 2076, EdmSchemaErrorSeverity.Error, sourceLocation, lineInfo.LineNumber, lineInfo.LinePosition); errors.Add(edmSchemaError); flag = false; } return(flag); }
/// <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); } }
public void Ctor_sets_properties() { var message = "Some message"; var errors = new EdmSchemaError[0]; var ex = new EdmSchemaErrorException(message, errors); Assert.Equal(message, ex.Message); Assert.Same(errors, ex.Errors); }
public void Can_add_get_error() { var mappingContext = new SimpleMappingContext(new EdmModel(DataSpace.SSpace), true); Assert.Empty(mappingContext.Errors); var error = new EdmSchemaError("bar", 0xF00, EdmSchemaErrorSeverity.Warning); mappingContext.Errors.Add(error); Assert.Same(error, mappingContext.Errors.Single()); }
private static void WriteError(EdmSchemaError e) { if (e.Severity == EdmSchemaErrorSeverity.Error) { Console.Write("Error: "); } else { Console.Write("Warning: "); } Console.WriteLine(e.Message); }
/// <summary> /// Check if all the SchemaErrors have the serverity of SchemaErrorSeverity.Warning /// </summary> /// <param name="schemaErrors"></param> /// <returns></returns> internal static bool CheckIfAllErrorsAreWarnings(IList <EdmSchemaError> schemaErrors) { int length = schemaErrors.Count; for (int i = 0; i < length; ++i) { EdmSchemaError error = schemaErrors[i]; if (error.Severity != EdmSchemaErrorSeverity.Warning) { return(false); } } return(true); }
private static ErrorInfo.Severity GetErrorInfoSeverity(EdmSchemaError error) { switch (error.Severity) { case EdmSchemaErrorSeverity.Error: return(ErrorInfo.Severity.ERROR); case EdmSchemaErrorSeverity.Warning: return(ErrorInfo.Severity.WARNING); default: Debug.Fail("Unexpected value for EdmSchemaErrorSeverity"); return(ErrorInfo.Severity.ERROR); } }
private void Init( ViewGenErrorCode errorCode, string message, IEnumerable <Cell> sourceCells, string debugMessage) { this.m_sourceCells = new List <Cell>(sourceCells); CellLabel cellLabel = this.m_sourceCells[0].CellLabel; string sourceLocation = cellLabel.SourceLocation; int startLineNumber = cellLabel.StartLineNumber; int startLinePosition = cellLabel.StartLinePosition; string message1 = ErrorLog.Record.InternalToString(message, debugMessage, this.m_sourceCells, errorCode, false); this.m_debugMessage = ErrorLog.Record.InternalToString(message, debugMessage, this.m_sourceCells, errorCode, true); this.m_mappingError = new EdmSchemaError(message1, (int)errorCode, EdmSchemaErrorSeverity.Error, sourceLocation, startLineNumber, startLinePosition); }
private EFObject EdmSchemaError2EFObject(EdmSchemaError error, EFArtifact defaultArtifactForError) { EFArtifact a = null; if (error.SchemaLocation != null) { a = _modelManager.GetArtifact(Utils.FileName2Uri(error.SchemaLocation)); } if (a == null) { a = defaultArtifactForError; } return(a.FindEFObjectForLineAndColumn(error.Line, error.Column)); }
public void Is_serializable() { var message = "Some message"; var errors = new EdmSchemaError[0]; var formatter = new BinaryFormatter(); EdmSchemaErrorException ex; using (var stream = new MemoryStream()) { formatter.Serialize(stream, new EdmSchemaErrorException(message, errors)); stream.Position = 0; ex = (EdmSchemaErrorException)formatter.Deserialize(stream); } Assert.Equal(message, ex.Message); Assert.Equal(errors, ex.Errors); }
private static void WriteError(EdmSchemaError e) { string error = string.Empty; if (e.Severity == EdmSchemaErrorSeverity.Error) { //Console.Write("Error: "); error += "Error: "; } else { //Console.Write("Warning: "); error += "Warning: "; } error += e.Message; Errors.Add(error); //Console.WriteLine(e.Message); }
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); }
public void GenerateModel_writes_errors_returned_from_ProcessModel() { var modelGenCache = new ModelGenErrorCache(); var mockPackage = new Mock <IEdmPackage>(); mockPackage.Setup(p => p.ModelGenErrorCache).Returns(modelGenCache); PackageManager.Package = mockPackage.Object; var mockHostContext = new Mock <ModelBuilderEngineHostContext>(); var mockModelBuilderSettings = CreateMockModelBuilderSettings(); var mockModelBuilderEngine = new Mock <ModelBuilderEngine> { CallBase = true }; var error = new EdmSchemaError("testError", 42, EdmSchemaErrorSeverity.Warning); mockModelBuilderEngine .Setup(m => m.GenerateModels(It.IsAny <string>(), It.IsAny <ModelBuilderSettings>(), It.IsAny <List <EdmSchemaError> >())) .Returns(new DbModel(new DbProviderInfo("System.Data.SqlClient", "2008"), Mock.Of <DbProviderManifest>())); mockModelBuilderEngine .Protected() .Setup( "ProcessModel", ItExpr.IsAny <DbModel>(), ItExpr.IsAny <string>(), ItExpr.IsAny <ModelBuilderSettings>(), ItExpr.IsAny <ModelBuilderEngineHostContext>(), ItExpr.IsAny <List <EdmSchemaError> >()) .Callback( (DbModel model, string storeModelNamespace, ModelBuilderSettings settings, ModelBuilderEngineHostContext hostContext, List <EdmSchemaError> errors) => errors.Add(error)); mockModelBuilderEngine.Object.GenerateModel(mockModelBuilderSettings.Object, Mock.Of <IVsUtils>(), mockHostContext.Object); mockModelBuilderEngine .Verify(m => m.GenerateModels( It.IsAny <string>(), It.IsAny <ModelBuilderSettings>(), It.IsAny <List <EdmSchemaError> >()), Times.Once()); mockHostContext.Verify(h => h.LogMessage(It.IsAny <string>()), Times.Exactly(3)); mockHostContext .Verify(h => h.LogMessage(It.IsRegex(Resources.Engine_ModelGenErrors.Substring(1, 20))), Times.Once()); mockHostContext .Verify(h => h.LogMessage(It.IsRegex(Resources.Engine_ModelGenException)), Times.Never()); Assert.Same(error, modelGenCache.GetErrors(mockModelBuilderSettings.Object.ModelPath).Single()); }
private void Init(bool isError, ViewGenErrorCode errorCode, string message, IEnumerable <Cell> sourceCells, string debugMessage) { m_sourceCells = new List <Cell>(sourceCells); Debug.Assert(m_sourceCells.Count > 0, "Error record must have at least one cell"); // For certain foreign key messages, we may need the SSDL line numbers and file names CellLabel label = m_sourceCells[0].CellLabel; string sourceLocation = label.SourceLocation; int lineNumber = label.StartLineNumber; int columnNumber = label.StartLinePosition; string userMessage = InternalToString(message, debugMessage, m_sourceCells, sourceLocation, errorCode, isError, false); m_debugMessage = InternalToString(message, debugMessage, m_sourceCells, sourceLocation, errorCode, isError, true); m_mappingError = new EdmSchemaError(userMessage, (int)errorCode, EdmSchemaErrorSeverity.Error, sourceLocation, lineNumber, columnNumber); }
internal bool ValidateTypeConditions(bool validateAmbiguity, IList <EdmSchemaError> errors, string sourceLocation) { // Verify that all types can be produced KeyToListMap <EntityType, LineInfo> unreachableEntityTypes; KeyToListMap <EntityType, LineInfo> unreachableIsTypeOfs; GetUnreachableTypes(validateAmbiguity, out unreachableEntityTypes, out unreachableIsTypeOfs); var valid = true; foreach (var unreachableEntityType in unreachableEntityTypes.KeyValuePairs) { var lineInfo = unreachableEntityType.Value.First(); var lines = StringUtil.ToCommaSeparatedString(unreachableEntityType.Value.Select(li => li.LineNumber)); var error = new EdmSchemaError( Strings.Mapping_FunctionImport_UnreachableType(unreachableEntityType.Key.FullName, lines), (int)StorageMappingErrorCode.MappingFunctionImportAmbiguousTypeConditions, EdmSchemaErrorSeverity.Error, sourceLocation, lineInfo.LineNumber, lineInfo.LinePosition); errors.Add(error); valid = false; } foreach (var unreachableIsTypeOf in unreachableIsTypeOfs.KeyValuePairs) { var lineInfo = unreachableIsTypeOf.Value.First(); var lines = StringUtil.ToCommaSeparatedString(unreachableIsTypeOf.Value.Select(li => li.LineNumber)); var isTypeOfDescription = StorageMslConstructs.IsTypeOf + unreachableIsTypeOf.Key.FullName + StorageMslConstructs.IsTypeOfTerminal; var error = new EdmSchemaError( Strings.Mapping_FunctionImport_UnreachableIsTypeOf(isTypeOfDescription, lines), (int)StorageMappingErrorCode.MappingFunctionImportAmbiguousTypeConditions, EdmSchemaErrorSeverity.Error, sourceLocation, lineInfo.LineNumber, lineInfo.LinePosition); errors.Add(error); valid = false; } return(valid); }
public void GenerateModel_combines_store_model_and_mapping_errors() { var storeModelError = new EdmSchemaError("storeError", 42, EdmSchemaErrorSeverity.Error); var errorMetadataProperty = MetadataProperty.Create( MetadataItemHelper.SchemaErrorsMetadataPropertyName, TypeUsage.CreateDefaultTypeUsage( PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String).GetCollectionType()), new List <EdmSchemaError> { storeModelError }); var entityType = EntityType.Create( "foo", "bar", DataSpace.SSpace, new string[0], new EdmMember[0], new[] { errorMetadataProperty }); var storeModel = new EdmModel(DataSpace.SSpace); storeModel.AddItem(entityType); var mappingContext = new SimpleMappingContext(storeModel, true); mappingContext.AddMapping( storeModel.Containers.Single(), EntityContainer.Create("C", DataSpace.CSpace, null, null, null)); mappingContext.Errors.Add(new EdmSchemaError("mappingError", 911, EdmSchemaErrorSeverity.Warning)); var mockModelGenerator = new Mock <ModelGenerator>(new ModelBuilderSettings(), "storeNamespace"); mockModelGenerator .Setup(g => g.CreateStoreModel()) .Returns(() => storeModel); mockModelGenerator .Setup(g => g.CreateMappingContext(It.IsAny <EdmModel>())) .Returns(() => mappingContext); var errors = new List <EdmSchemaError>(); mockModelGenerator.Object.GenerateModel(errors); Assert.Equal(new[] { storeModelError, mappingContext.Errors.Single() }, errors); }
public void CollectStoreModelErrors_returns_errors_from_function_return_rowtypes() { var edmSchemaError = new EdmSchemaError("msg", 42, EdmSchemaErrorSeverity.Error); var errorMetadataProperty = MetadataProperty.Create( MetadataItemHelper.SchemaErrorsMetadataPropertyName, TypeUsage.CreateDefaultTypeUsage( PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String).GetCollectionType()), new List <EdmSchemaError> { edmSchemaError }); var rowType = RowType.Create(new EdmProperty[0], new[] { errorMetadataProperty }); var function = EdmFunction.Create( "foo", "bar", DataSpace.SSpace, new EdmFunctionPayload { ReturnParameters = new[] { FunctionParameter.Create( "ReturnType", rowType, ParameterMode.ReturnValue) } }, null); var model = new EdmModel(DataSpace.SSpace); model.AddItem(function); var schemaErrors = ModelGenerator.CollectStoreModelErrors(model); Assert.NotNull(schemaErrors); Assert.Equal(1, schemaErrors.Count); Assert.Same(edmSchemaError, schemaErrors.Single()); }
private void AddError( ErrorCode errorCode, EdmSchemaErrorSeverity severity, string sourceLocation, int lineNumber, int linePosition, object message) { string message1 = message as string; EdmSchemaError error; if (message1 != null) { error = new EdmSchemaError(message1, (int)errorCode, severity, sourceLocation, lineNumber, linePosition); } else { Exception exception = message as Exception; error = exception == null ? new EdmSchemaError(message.ToString(), (int)errorCode, severity, sourceLocation, lineNumber, linePosition) : new EdmSchemaError(exception.Message, (int)errorCode, severity, sourceLocation, lineNumber, linePosition, exception); } this.Schema.AddError(error); }
/// <summary> /// /// </summary> /// <param name="errorCode"></param> /// <param name="severity"></param> /// <param name="source"></param> /// <param name="lineNumber"></param> /// <param name="linePosition"></param> /// <param name="message"></param> private void AddError(ErrorCode errorCode, EdmSchemaErrorSeverity severity, string sourceLocation, int lineNumber, int linePosition, object message) { EdmSchemaError error = null; string messageString = message as string; if (messageString != null) { error = new EdmSchemaError(messageString, (int)errorCode, severity, sourceLocation, lineNumber, linePosition); } else { Exception ex = message as Exception; if (ex != null) { error = new EdmSchemaError(ex.Message, (int)errorCode, severity, sourceLocation, lineNumber, linePosition, ex); } else { error = new EdmSchemaError(message.ToString(), (int)errorCode, severity, sourceLocation, lineNumber, linePosition); } } Schema.AddError(error); }
internal Record(EdmSchemaError error) { this.m_debugMessage = error.ToString(); this.m_mappingError = error; }
internal void AddError(EdmSchemaError error) { _errors.Add(error); }
private bool TryConvertToPropertyMappings( StructuralType structuralType, RowType cTypeTvfElementType, RowType sTypeTvfElementType, EdmFunction functionImport, FunctionImportStructuralTypeMappingKB functionImportKB, IXmlLineInfo navLineInfo, out List <PropertyMapping> propertyMappings) { propertyMappings = new List <PropertyMapping>(); // Gather and validate structuralType property mappings. var errorFound = false; foreach (EdmProperty property in TypeHelpers.GetAllStructuralMembers(structuralType)) { // Only scalar property mappings are supported at the moment. if (!Helper.IsScalarType(property.TypeUsage.EdmType)) { var error = new EdmSchemaError( Strings.Mapping_Invalid_CSide_ScalarProperty(property.Name), (int)MappingErrorCode.InvalidTypeInScalarProperty, EdmSchemaErrorSeverity.Error, m_sourceLocation, navLineInfo.LineNumber, navLineInfo.LinePosition); m_parsingErrors.Add(error); errorFound = true; continue; } string columnName = null; IXmlLineInfo columnMappingLineInfo = null; FunctionImportReturnTypeStructuralTypeColumnRenameMapping columnRenameMapping; bool explicitPropertyMapping; if (functionImportKB.ReturnTypeColumnsRenameMapping.TryGetValue(property.Name, out columnRenameMapping)) { explicitPropertyMapping = true; columnName = columnRenameMapping.GetRename(structuralType, out columnMappingLineInfo); } else { explicitPropertyMapping = false; columnName = property.Name; } columnMappingLineInfo = columnMappingLineInfo != null && columnMappingLineInfo.HasLineInfo() ? columnMappingLineInfo : navLineInfo; EdmProperty column; if (sTypeTvfElementType.Properties.TryGetValue(columnName, false, out column)) { Debug.Assert(cTypeTvfElementType.Properties.Contains(columnName), "cTypeTvfElementType.Properties.Contains(columnName)"); var cTypeColumn = cTypeTvfElementType.Properties[columnName]; if (ValidateFunctionImportMappingResultTypeCompatibility(property.TypeUsage, cTypeColumn.TypeUsage)) { propertyMappings.Add(new ScalarPropertyMapping(property, column)); } else { var error = new EdmSchemaError( GetInvalidMemberMappingErrorMessage(property, column), (int)MappingErrorCode.IncompatibleMemberMapping, EdmSchemaErrorSeverity.Error, m_sourceLocation, columnMappingLineInfo.LineNumber, columnMappingLineInfo.LinePosition); m_parsingErrors.Add(error); errorFound = true; } } else { if (explicitPropertyMapping) { AddToSchemaErrorsWithMemberInfo( Strings.Mapping_InvalidContent_Column, columnName, MappingErrorCode.InvalidStorageMember, m_sourceLocation, columnMappingLineInfo, m_parsingErrors); errorFound = true; } else { var error = new EdmSchemaError( Strings.Mapping_FunctionImport_PropertyNotMapped( property.Name, structuralType.FullName, functionImport.Identity), (int)MappingErrorCode.MappingFunctionImportReturnTypePropertyNotMapped, EdmSchemaErrorSeverity.Error, m_sourceLocation, columnMappingLineInfo.LineNumber, columnMappingLineInfo.LinePosition); m_parsingErrors.Add(error); errorFound = true; } } } // Make sure that propertyMappings is in the order of properties of the structuredType. // The rest of the code depends on it. Debug.Assert( errorFound || TypeHelpers.GetAllStructuralMembers(structuralType).Count == propertyMappings.Count && TypeHelpers.GetAllStructuralMembers(structuralType).Cast <EdmMember>().Zip(propertyMappings) .All(ppm => ppm.Key.EdmEquals(ppm.Value.Property)), "propertyMappings order does not correspond to the order of properties in the structuredType."); return(!errorFound); }
// effects: Given a container, ensures that all entity/association // sets in container on the C-side have been mapped private static ErrorLog EnsureAllCSpaceContainerSetsAreMapped( IEnumerable <Cell> cells, StorageEntityContainerMapping containerMapping) { var mappedExtents = new Set <EntitySetBase>(); string mslFileLocation = null; EntityContainer container = null; // Determine the container and name of the file while determining // the set of mapped extents in the cells foreach (var cell in cells) { mappedExtents.Add(cell.CQuery.Extent); mslFileLocation = cell.CellLabel.SourceLocation; // All cells are from the same container container = cell.CQuery.Extent.EntityContainer; } Debug.Assert(container != null); var missingExtents = new List <EntitySetBase>(); // Go through all the extents in the container and determine // extents that are missing foreach (var extent in container.BaseEntitySets) { if (mappedExtents.Contains(extent) == false && !(containerMapping.HasQueryViewForSetMap(extent.Name))) { var associationSet = extent as AssociationSet; if (associationSet == null || !associationSet.ElementType.IsForeignKey) { missingExtents.Add(extent); } } } var errorLog = new ErrorLog(); // If any extent is not mapped, add an error if (missingExtents.Count > 0) { var extentBuilder = new StringBuilder(); var isFirst = true; foreach (var extent in missingExtents) { if (isFirst == false) { extentBuilder.Append(", "); } isFirst = false; extentBuilder.Append(extent.Name); } var message = Strings.ViewGen_Missing_Set_Mapping(extentBuilder); // Find the cell with smallest line number - so that we can // point to the beginning of the file var lowestLineNum = -1; Cell smallestCell = null; foreach (var cell in cells) { if (lowestLineNum == -1 || cell.CellLabel.StartLineNumber < lowestLineNum) { smallestCell = cell; lowestLineNum = cell.CellLabel.StartLineNumber; } } Debug.Assert(smallestCell != null && lowestLineNum >= 0); var edmSchemaError = new EdmSchemaError( message, (int)ViewGenErrorCode.MissingExtentMapping, EdmSchemaErrorSeverity.Error, containerMapping.SourceLocation, containerMapping.StartLineNumber, containerMapping.StartLinePosition, null); var record = new ErrorLog.Record(edmSchemaError); errorLog.AddEntry(record); } return(errorLog); }