private IEnumerable <string> ComputePrincipalKeyPropertiesNotFoundInPrincipalProperties() { List <string> strs = null; IEnumerator <IEdmStructuralProperty> enumerator = this.PrincipalEnd.EntityType.Key().GetEnumerator(); using (enumerator) { Func <CsdlPropertyReference, bool> func = null; while (enumerator.MoveNext()) { IEdmStructuralProperty current = enumerator.Current; CsdlReferentialConstraintRole principal = this.constraint.Principal; IEnumerable <CsdlPropertyReference> properties = principal.Properties; if (func == null) { func = (CsdlPropertyReference reference) => reference.PropertyName == current.Name; } CsdlPropertyReference csdlPropertyReference = properties.Where <CsdlPropertyReference>(func).FirstOrDefault <CsdlPropertyReference>(); if (csdlPropertyReference != null) { continue; } strs = CsdlSemanticsElement.AllocateAndAdd <string>(strs, current.Name); } } List <string> strs1 = strs; IEnumerable <string> strs2 = strs1; if (strs1 == null) { strs2 = Enumerable.Empty <string>(); } return(strs2); }
private IEnumerable <string> ComputePrincipalKeyPropertiesNotFoundInPrincipalProperties() { List <string> properties = null; foreach (IEdmStructuralProperty principalKeyProperty in this.PrincipalEnd.EntityType.Key()) { CsdlReferentialConstraintRole principalEnd = this.constraint.Principal; CsdlPropertyReference correspondingPrimaryEndReference = (from reference in principalEnd.Properties where reference.PropertyName == principalKeyProperty.Name select reference).FirstOrDefault(); if (correspondingPrimaryEndReference == null) { properties = AllocateAndAdd(properties, principalKeyProperty.Name); } } return(properties ?? Enumerable.Empty <string>()); }
private IEnumerable <IEdmStructuralProperty> ComputeDeclaredKey() { if (this.entity.Key == null) { return(null); } else { List <IEdmStructuralProperty> edmStructuralProperties = new List <IEdmStructuralProperty>(); IEnumerator <CsdlPropertyReference> enumerator = this.entity.Key.Properties.GetEnumerator(); using (enumerator) { Func <IEdmProperty, bool> func = null; while (enumerator.MoveNext()) { CsdlPropertyReference current = enumerator.Current; IEdmStructuralProperty edmStructuralProperty = base.FindProperty(current.PropertyName) as IEdmStructuralProperty; if (edmStructuralProperty == null) { IEnumerable <IEdmProperty> declaredProperties = base.DeclaredProperties; if (func == null) { func = (IEdmProperty p) => p.Name == current.PropertyName; } edmStructuralProperty = declaredProperties.SingleOrDefault <IEdmProperty>(func) as IEdmStructuralProperty; if (edmStructuralProperty == null) { edmStructuralProperties.Add(new UnresolvedProperty(this, current.PropertyName, base.Location)); } else { edmStructuralProperties.Add(edmStructuralProperty); } } else { edmStructuralProperties.Add(edmStructuralProperty); } } } return(edmStructuralProperties); } }
private IEnumerable <IEdmStructuralProperty> ComputeDependentProperties() { List <IEdmStructuralProperty> edmStructuralProperties = new List <IEdmStructuralProperty>(); IEdmEntityType entityType = this.DependentEnd.EntityType; var principalRoleType = this.PrincipalEnd.EntityType; CsdlReferentialConstraintRole principal = this.constraint.Principal; CsdlReferentialConstraintRole dependent = this.constraint.Dependent; if (principalRoleType.Key().Count <IEdmStructuralProperty>() != principal.Properties.Count <CsdlPropertyReference>() || principal.Properties.Count <CsdlPropertyReference>() != dependent.Properties.Count <CsdlPropertyReference>() || this.PrincipalKeyPropertiesNotFoundInPrincipalProperties.Count <string>() != 0 || this.DependentPropertiesNotFoundInDependentType.Count <string>() != 0) { edmStructuralProperties = new List <IEdmStructuralProperty>(); foreach (CsdlPropertyReference property in dependent.Properties) { EdmError[] edmError = new EdmError[1]; edmError[0] = new EdmError(base.Location, EdmErrorCode.TypeMismatchRelationshipConstraint, Strings.CsdlSemantics_ReferentialConstraintMismatch); edmStructuralProperties.Add(new BadProperty(entityType, property.PropertyName, edmError)); } } else { IEnumerator <IEdmStructuralProperty> enumerator = this.PrincipalEnd.EntityType.Key().GetEnumerator(); using (enumerator) { Func <CsdlPropertyReference, bool> func = null; while (enumerator.MoveNext()) { IEdmStructuralProperty current = enumerator.Current; IEnumerable <CsdlPropertyReference> properties = principal.Properties; if (func == null) { func = (CsdlPropertyReference reference) => principalRoleType.FindProperty(reference.PropertyName).Equals(current); } CsdlPropertyReference csdlPropertyReference = properties.Where <CsdlPropertyReference>(func).FirstOrDefault <CsdlPropertyReference>(); int num = principal.IndexOf(csdlPropertyReference); CsdlPropertyReference csdlPropertyReference1 = dependent.Properties.ElementAt <CsdlPropertyReference>(num); IEdmStructuralProperty edmStructuralProperty = entityType.FindProperty(csdlPropertyReference1.PropertyName) as IEdmStructuralProperty; edmStructuralProperties.Add(edmStructuralProperty); } } } return(edmStructuralProperties); }
private IEnumerable <IEdmStructuralProperty> ComputeDependentProperties() { // Sort the ReferentialConstraint principal/dependent property pairs into the order of the principal end. // If any part of the constraint is bad, return all dependent properties as bad. List <IEdmStructuralProperty> properties = new List <IEdmStructuralProperty>(); IEdmEntityType dependentRoleType = this.DependentEnd.EntityType; IEdmEntityType principalRoleType = this.PrincipalEnd.EntityType; CsdlReferentialConstraintRole principalEnd = this.constraint.Principal; CsdlReferentialConstraintRole dependentEnd = this.constraint.Dependent; if ((principalRoleType.Key().Count() == principalEnd.Properties.Count() && principalEnd.Properties.Count() == dependentEnd.Properties.Count()) && this.PrincipalKeyPropertiesNotFoundInPrincipalProperties.Count() == 0 && this.DependentPropertiesNotFoundInDependentType.Count() == 0) { foreach (IEdmStructuralProperty principalKeyProperty in this.PrincipalEnd.EntityType.Key()) { CsdlPropertyReference correspondingPrimaryEndReference = (from reference in principalEnd.Properties where principalRoleType.FindProperty(reference.PropertyName).Equals(principalKeyProperty) select reference).FirstOrDefault(); int correspondingPrimaryEndIndex = principalEnd.IndexOf(correspondingPrimaryEndReference); CsdlPropertyReference dependentEndReference = dependentEnd.Properties.ElementAt(correspondingPrimaryEndIndex); IEdmStructuralProperty dependentProperty = dependentRoleType.FindProperty(dependentEndReference.PropertyName) as IEdmStructuralProperty; properties.Add(dependentProperty); } } else { properties = new List <IEdmStructuralProperty>(); foreach (CsdlPropertyReference prop in dependentEnd.Properties) { properties.Add(new BadProperty(dependentRoleType, prop.PropertyName, new EdmError[] { new EdmError(this.Location, EdmErrorCode.TypeMismatchRelationshipConstraint, Edm.Strings.CsdlSemantics_ReferentialConstraintMismatch) })); } } return(properties); }
public void ParseCsdlEntityTypeWithMembersWorksAsExpected() { string json = @"""Supplier"": { ""$Kind"": ""EntityType"", ""$Key"": [ ""ID"" ], ""ID"": {}, ""Name"": { ""$Nullable"": true }, ""Address"": { ""$Type"": ""self.Address"" }, ""Concurrency"": { ""$Type"": ""Edm.Int32"" }, ""Products"": { ""$Kind"": ""NavigationProperty"", ""$Partner"": ""Supplier"", ""$Collection"": true, ""$Type"": ""self.Product"" } }"; CsdlEntityType entityType = ParseCsdlSchemaElement(json, SchemaJsonParser.ParseCsdlEntityType); Assert.NotNull(entityType); Assert.Equal("Supplier", entityType.Name); Assert.False(entityType.IsAbstract); Assert.False(entityType.IsOpen); Assert.Null(entityType.BaseTypeName); Assert.False(entityType.HasStream); CsdlPropertyReference propertyRef = Assert.Single(entityType.Key.Properties); Assert.Equal("ID", propertyRef.PropertyName); Assert.Equal(4, entityType.StructuralProperties.Count()); // ID CsdlProperty id = entityType.StructuralProperties.FirstOrDefault(p => p.Name == "ID"); Assert.NotNull(id); CsdlStringTypeReference stringType = Assert.IsType <CsdlStringTypeReference>(id.Type); Assert.False(stringType.IsUnbounded); Assert.Null(stringType.IsUnicode); Assert.Null(stringType.MaxLength); Assert.False(stringType.IsNullable); // Name CsdlProperty name = entityType.StructuralProperties.FirstOrDefault(p => p.Name == "Name"); Assert.NotNull(name); stringType = Assert.IsType <CsdlStringTypeReference>(name.Type); Assert.True(stringType.IsNullable); // Address CsdlProperty address = entityType.StructuralProperties.FirstOrDefault(p => p.Name == "Address"); Assert.NotNull(address); CsdlNamedTypeReference namedType = Assert.IsType <CsdlNamedTypeReference>(address.Type); Assert.Equal("self.Address", namedType.FullName); // Concurrency CsdlProperty concurrency = entityType.StructuralProperties.FirstOrDefault(p => p.Name == "Concurrency"); Assert.NotNull(concurrency); CsdlPrimitiveTypeReference primitiveType = Assert.IsType <CsdlPrimitiveTypeReference>(concurrency.Type); Assert.Equal(EdmPrimitiveTypeKind.Int32, primitiveType.Kind); Assert.False(primitiveType.IsNullable); // Products CsdlNavigationProperty products = Assert.Single(entityType.NavigationProperties); Assert.Equal("Products", products.Name); Assert.Equal("Collection(self.Product)", products.Type); Assert.Equal("Supplier", products.PartnerPath.Path); }