/// <summary> /// Initializes a new instance of AssociationEndMember /// </summary> /// <param name="name"> name of the association end member </param> /// <param name="endRefType"> Ref type that this end refers to </param> /// <param name="multiplicity"> multiplicity of the end </param> internal AssociationEndMember( string name, RefType endRefType, RelationshipMultiplicity multiplicity) : base(name, endRefType, multiplicity) { }
public void Create_throws_argument_exception_when_called_with_invalid_arguments() { var entityType = new EntityType("Source", "Namespace", DataSpace.CSpace); var refType = new RefType(entityType); var metadataProperty = new MetadataProperty( "MetadataProperty", TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)), "value"); Assert.Throws<ArgumentException>( () => AssociationEndMember.Create( null, refType, RelationshipMultiplicity.Many, OperationAction.Cascade, new[] { metadataProperty })); Assert.Throws<ArgumentException>( () => AssociationEndMember.Create( String.Empty, refType, RelationshipMultiplicity.Many, OperationAction.Cascade, new[] { metadataProperty })); Assert.Throws<ArgumentNullException>( () => AssociationEndMember.Create( "AssociationEndMember", null, RelationshipMultiplicity.Many, OperationAction.Cascade, new[] { metadataProperty })); }
// <summary> // Initializes a new instance of RelationshipEndMember // </summary> // <param name="name"> name of the relationship end member </param> // <param name="endRefType"> Ref type that this end refers to </param> // <param name="multiplicity"> The multiplicity of this relationship end </param> // <exception cref="System.ArgumentNullException">Thrown if name or endRefType arguments is null</exception> // <exception cref="System.ArgumentException">Thrown if name argument is empty string</exception> internal RelationshipEndMember( string name, RefType endRefType, RelationshipMultiplicity multiplicity) : base(name, TypeUsage.Create( endRefType, new FacetValues { Nullable = false })) { _relationshipMultiplicity = multiplicity; _deleteBehavior = OperationAction.None; }
internal override bool ResolveNameAndSetTypeUsage( Converter.ConversionCache convertedItemCache, Dictionary<SchemaElement, GlobalItem> newGlobalItems) { if (_typeUsage == null) { Debug.Assert(!(_type is ScalarType)); var edmType = (EdmType)Converter.LoadSchemaElement(_type, _type.Schema.ProviderManifest, convertedItemCache, newGlobalItems); var entityType = edmType as EntityType; Debug.Assert(entityType != null); var refType = new RefType(entityType); refType.AddMetadataProperties(OtherContent); _typeUsage = TypeUsage.Create(refType); } return true; }
/// <summary> /// Creates a read-only AssociationEndMember instance. /// </summary> /// <param name="name">The name of the association end member.</param> /// <param name="endRefType">The reference type for the end.</param> /// <param name="multiplicity">The multiplicity of the end.</param> /// <param name="deleteAction">Flag that indicates the delete behavior of the end.</param> /// <param name="metadataProperties">Metadata properties to be associated with the instance.</param> /// <returns>The newly created AssociationEndMember instance.</returns> /// <exception cref="ArgumentException">The specified name is null or empty.</exception> /// <exception cref="ArgumentNullException">The specified reference type is null.</exception> public static AssociationEndMember Create( string name, RefType endRefType, RelationshipMultiplicity multiplicity, OperationAction deleteAction, IEnumerable<MetadataProperty> metadataProperties) { Check.NotEmpty(name, "name"); Check.NotNull(endRefType, "endRefType"); var instance = new AssociationEndMember(name, endRefType, multiplicity); instance.DeleteBehavior = deleteAction; if (metadataProperties != null) { instance.AddMetadataProperties(metadataProperties.ToList()); } instance.SetReadOnly(); return instance; }
internal IEnumerable <PropertyRef> GetKeyPropertyRefs() { md.EntityTypeBase entityType = null; md.RefType refType = null; if (TypeHelpers.TryGetEdmType(m_type, out refType)) { entityType = refType.ElementType; } else { entityType = TypeHelpers.GetEdmType <md.EntityTypeBase>(m_type); } // Walk through the list of keys of the entity type, and find their analogs in the // "flattened" type foreach (var p in entityType.KeyMembers) { // Eventually this could be RelationshipEndMember, but currently only properties are suppported as key members PlanCompiler.Assert(p is md.EdmProperty, "Non-EdmProperty key members are not supported"); var spr = new SimplePropertyRef(p); yield return(spr); } }
public void Create_sets_properties_and_seals_the_instance() { var entityType = new EntityType("Source", "Namespace", DataSpace.CSpace); var refType = new RefType(entityType); var metadataProperty = new MetadataProperty( "MetadataProperty", TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)), "value"); var associationEnd = AssociationEndMember.Create( "AssociationEndMember", refType, RelationshipMultiplicity.Many, OperationAction.Cascade, new[] { metadataProperty }); Assert.Equal("AssociationEndMember", associationEnd.Name); Assert.Same(entityType, associationEnd.GetEntityType()); Assert.Equal(RelationshipMultiplicity.Many, associationEnd.RelationshipMultiplicity); Assert.Equal(OperationAction.Cascade, associationEnd.DeleteBehavior); Assert.Same(metadataProperty, associationEnd.MetadataProperties.SingleOrDefault(p => p.Name == "MetadataProperty")); Assert.True(associationEnd.IsReadOnly); }
/// <summary>Convert CSpace TypeMetadata into OSpace TypeMetadata</summary> /// <param name="clrType"></param> /// <returns>OSpace type metadata</returns> private EdmType ConvertOSpaceToCSpaceType(EdmType clrType) { EdmType cdmType = null; if (Helper.IsCollectionType(clrType)) { var elemType = ConvertOSpaceToCSpaceType(((CollectionType)clrType).TypeUsage.EdmType); cdmType = new CollectionType(elemType); } else if (Helper.IsRowType(clrType)) { var cdmProperties = new List<EdmProperty>(); var rowType = (RowType)clrType; foreach (var column in rowType.Properties) { var cdmPropertyType = ConvertOSpaceToCSpaceType(column.TypeUsage.EdmType); var cdmPorperty = new EdmProperty(column.Name, TypeUsage.Create(cdmPropertyType)); cdmProperties.Add(cdmPorperty); } cdmType = new RowType(cdmProperties, rowType.InitializerMetadata); } else if (Helper.IsRefType(clrType)) { cdmType = new RefType((EntityType)(ConvertOSpaceToCSpaceType(((RefType)clrType).ElementType))); } else { cdmType = ((ObjectTypeMapping)GetMap(clrType)).EdmType; } Debug.Assert((null != cdmType), "null converted clr type"); return cdmType; }
protected virtual void Visit(RefType refType) { Visit(refType.BaseType); Visit(refType.ElementType); }
public void Throws_if_required_related_end_is_missing() { var entityReferenceMock = MockHelper.CreateMockEntityReference<object>(refreshedValue: null); var associationType = new AssociationType( name: "associationName", namespaceName: "associationNamespace", foreignKey: false, dataSpace: DataSpace.CSpace); entityReferenceMock.Setup(m => m.RelationMetadata).Returns(associationType); var refType = new RefType(new EntityType(name: "entityTypeName", namespaceName: "entityTypeNamespace", dataSpace: DataSpace.CSpace)); var toEndMember = new AssociationEndMember( name: "toEndMember", endRefType: refType, multiplicity: RelationshipMultiplicity.One); entityReferenceMock.Setup(m => m.ToEndMember).Returns(toEndMember); Assert.Equal( Strings.EntityReference_LessThanExpectedRelatedEntitiesFound, Assert.Throws<InvalidOperationException>( () => ExceptionHelpers.UnwrapAggregateExceptions( () => entityReferenceMock.Object.LoadAsync(MergeOption.NoTracking, CancellationToken.None).Wait())).Message); }
protected override void Visit(RefType refType) { int index; if (!AddObjectToSeenListAndHashBuilder(refType, out index)) { return; } AddObjectStartDumpToHashBuilder(refType, index); #region Inner data visit AddObjectContentToHashBuilder(refType.Identity); // Identity contains Name, NamespaceName and FullName base.Visit(refType); #endregion AddObjectEndDumpToHashBuilder(); }
private static bool TryGetCommonType(RefType refType1, RefType reftype2, out EdmType commonType) { DebugCheck.NotNull(refType1.ElementType); DebugCheck.NotNull(reftype2.ElementType); if (!TryGetCommonType(refType1.ElementType, reftype2.ElementType, out commonType)) { return false; } commonType = new RefType((EntityType)commonType); return true; }
private static Mock<RelatedEnd> CreateMockRelatedEnd() { var relatedEndMock = new Mock<RelatedEnd> { CallBase = true }; var associationType = new AssociationType( name: "associationName", namespaceName: "associationNamespace", foreignKey: true, dataSpace: DataSpace.CSpace); var associationSet = new AssociationSet(name: "associationSetName", associationType: associationType); var refType = new RefType(new EntityType(name: "entityTypeName", namespaceName: "entityTypeNamespace", dataSpace: DataSpace.CSpace)); var toEndMember = new AssociationEndMember( name: "toEndMember", endRefType: refType, multiplicity: RelationshipMultiplicity.Many); associationSet.AddAssociationSetEnd(new AssociationSetEnd(new EntitySet(), associationSet, toEndMember)); relatedEndMock.Setup(m => m.RelationshipSet).Returns(associationSet); relatedEndMock.Setup(m => m.TargetRoleName).Returns("toEndMember"); relatedEndMock.Setup(m => m.EntityWrapperFactory).Returns(CreateMockEntityWrapperFactory().Object); return relatedEndMock; }
private static bool TryGetCommonType(RefType refType1, RefType reftype2, out EdmType commonType) { Debug.Assert(refType1.ElementType != null && reftype2.ElementType != null); if (!TryGetCommonType(refType1.ElementType, reftype2.ElementType, out commonType)) { return false; } commonType = new RefType((EntityType)commonType); return true; }