public void Can_get_and_set_ends_via_wrapper_properties()
        {
            var associationType
                = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)
                      {
                          SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace)),
                          TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace))
                      };

            var associationSet = new AssociationSet("A", associationType);

            Assert.Null(associationSet.SourceSet);
            Assert.Null(associationSet.TargetSet);

            var sourceEntitySet = new EntitySet();

            associationSet.SourceSet = sourceEntitySet;

            var targetEntitySet = new EntitySet();

            associationSet.TargetSet = targetEntitySet;

            Assert.Same(sourceEntitySet, associationSet.SourceSet);
            Assert.Same(targetEntitySet, associationSet.TargetSet);
        }
        /// <summary>
        ///     Initialize Metadata for an AssociationSet
        /// </summary>
        internal AssociationSetMetadata(Set<EntitySet> affectedTables, AssociationSet associationSet, MetadataWorkspace workspace)
        {
            // If there is only 1 table, there can be no ambiguity about the "destination" of a relationship, so such
            // sets are not typically required.
            var isRequired = 1 < affectedTables.Count;

            // determine the ends of the relationship
            var ends = associationSet.AssociationSetEnds;

            // find collocated entities
            foreach (var table in affectedTables)
            {
                // Find extents influencing the table
                var influencingExtents = MetadataHelper.GetInfluencingEntitySetsForTable(table, workspace);

                foreach (var influencingExtent in influencingExtents)
                {
                    foreach (var end in ends)
                    {
                        // If the extent is an end of the relationship and we haven't already added it to the
                        // required set...
                        if (end.EntitySet.EdmEquals(influencingExtent))
                        {
                            if (isRequired)
                            {
                                AddEnd(ref RequiredEnds, end.CorrespondingAssociationEndMember);
                            }
                            else if (null == RequiredEnds
                                     || !RequiredEnds.Contains(end.CorrespondingAssociationEndMember))
                            {
                                AddEnd(ref OptionalEnds, end.CorrespondingAssociationEndMember);
                            }
                        }
                    }
                }
            }

            // fix Required and Optional sets
            FixSet(ref RequiredEnds);
            FixSet(ref OptionalEnds);

            // for associations with referential constraints, the principal end is always interesting
            // since its key values may take precedence over the key values of the dependent end
            foreach (var constraint in associationSet.ElementType.ReferentialConstraints)
            {
                // FromRole is the principal end in the referential constraint
                var principalEnd = (AssociationEndMember)constraint.FromRole;

                if (!RequiredEnds.Contains(principalEnd)
                    &&
                    !OptionalEnds.Contains(principalEnd))
                {
                    AddEnd(ref IncludedValueEnds, principalEnd);
                }
            }

            FixSet(ref IncludedValueEnds);
        }
 protected virtual void Visit(AssociationSet associationSet)
 {
     Visit(associationSet.ElementType);
     Visit(associationSet.EntityContainer);
     foreach (var end in associationSet.AssociationSetEnds)
     {
         Visit(end);
     }
 }
        public void Can_get_association_set()
        {
            var entitySet = new EntitySet();
            var associationSet = new AssociationSet("AS", new AssociationType());

            var associationSetMapping
                = new StorageAssociationSetMapping(associationSet, entitySet);

            Assert.Same(associationSet, associationSetMapping.AssociationSet);
        }
        public void Can_get_association_set()
        {
            var entitySet = new EntitySet();
            var associationSet = new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace));

            var associationSetMapping
                = new StorageAssociationSetMapping(associationSet, entitySet);

            Assert.Same(associationSet, associationSetMapping.AssociationSet);
        }
        public void Can_get_table()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var entitySet = new EntitySet("ES", null, null, null, entityType);
            var associationSet = new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace));

            var associationSetMapping
                = new StorageAssociationSetMapping(associationSet, entitySet);

            Assert.Same(entityType, associationSetMapping.Table);
        }
        public void Can_get_table()
        {
            var entityType = new EntityType();
            var entitySet = new EntitySet("ES", null, null, null, entityType);
            var associationSet = new AssociationSet("AS", new AssociationType());

            var associationSetMapping
                = new StorageAssociationSetMapping(associationSet, entitySet);

            Assert.Same(entityType, associationSetMapping.Table);
        }
        internal StorageAssociationSetModificationFunctionMapping(
            AssociationSet associationSet,
            StorageModificationFunctionMapping deleteFunctionMapping,
            StorageModificationFunctionMapping insertFunctionMapping)
        {
            Contract.Requires(associationSet != null);

            AssociationSet = associationSet;
            DeleteFunctionMapping = deleteFunctionMapping;
            InsertFunctionMapping = insertFunctionMapping;
        }
        public void Cannot_create_with_null_argument()
        {
            var associationType = new AssociationType("AT", "N", false, DataSpace.CSpace);
            var associationSet = new AssociationSet("AS", associationType);

            Assert.Equal(
                "members",
                Assert.Throws<ArgumentNullException>(
                    () => new ModificationFunctionMemberPath(
                        null, associationSet)).ParamName);
        }
        /// <summary>
        /// Initalizes a new AssociationSetModificationFunctionMapping instance.
        /// </summary>
        /// <param name="associationSet">An association set.</param>
        /// <param name="deleteFunctionMapping">A delete function mapping.</param>
        /// <param name="insertFunctionMapping">An insert function mapping.</param>
        public AssociationSetModificationFunctionMapping(
            AssociationSet associationSet,
            ModificationFunctionMapping deleteFunctionMapping,
            ModificationFunctionMapping insertFunctionMapping)
        {
            Check.NotNull(associationSet, "associationSet");

            _associationSet = associationSet;
            _deleteFunctionMapping = deleteFunctionMapping;
            _insertFunctionMapping = insertFunctionMapping;
        }
        internal StorageAssociationSetModificationFunctionMapping(
            AssociationSet associationSet,
            StorageModificationFunctionMapping deleteFunctionMapping,
            StorageModificationFunctionMapping insertFunctionMapping)
        {
            DebugCheck.NotNull(associationSet);

            AssociationSet = associationSet;
            DeleteFunctionMapping = deleteFunctionMapping;
            InsertFunctionMapping = insertFunctionMapping;
        }
        /// <summary>
        /// Initializes a new AssociationSetMapping instance.
        /// </summary>
        /// <param name="associationSet">The association set to be mapped.</param>
        /// <param name="storeEntitySet">The store entity set to be mapped.</param>
        /// <param name="containerMapping">The parent container mapping.</param>
        public AssociationSetMapping(AssociationSet associationSet, EntitySet storeEntitySet, EntityContainerMapping containerMapping)
            : base(containerMapping)
        {
            Check.NotNull(associationSet, "associationSet");
            Check.NotNull(storeEntitySet, "storeEntitySet");

            _associationSet = associationSet;
            _associationTypeMapping = new AssociationTypeMapping(associationSet.ElementType, this);
            _associationTypeMapping.MappingFragment
                = new MappingFragment(storeEntitySet, _associationTypeMapping, false);
        }
 // <summary>
 //     A name derived from a *:* association will be: FK_[Association Name]_[End Name]. Note that we are
 //     getting the association name for *one* of the SSDL associations that are inferred from a CSDL *:*
 //     association. The 'principalEnd' corresponds to the end of the *:* association that will become
 //     the principal end in the 1:* association (where the * end is the newly-constructed entity corresponding
 //     to the link table)
 // </summary>
 internal static string GetStorageAssociationSetNameFromManyToMany(AssociationSet associationSet, AssociationEndMember principalEnd)
 {
     Debug.Assert(associationSet != null, "AssociationSet should not be null");
     Debug.Assert(principalEnd != null, "The principal end cannot be null");
     var associationSetName = String.Empty;
     if (associationSet != null
         && principalEnd != null)
     {
         associationSetName = String.Format(
             CultureInfo.CurrentCulture, Resources.CodeViewManyToManyAssocName, associationSet.Name, principalEnd.Name);
     }
     return associationSetName;
 }
        internal StorageModificationFunctionMemberPath(IEnumerable<EdmMember> members, AssociationSet associationSetNavigation)
        {
            Contract.Requires(members != null);

            Members = new ReadOnlyCollection<EdmMember>(new List<EdmMember>(members));

            if (null != associationSetNavigation)
            {
                Debug.Assert(2 == Members.Count, "Association bindings must always consist of the end and the key");

                // find the association set end
                AssociationSetEnd = associationSetNavigation.AssociationSetEnds[Members[1].Name];
            }
        }
        public void Can_remove_set_from_container()
        {
            var entityContainer = new EntityContainer("C", DataSpace.CSpace);
            var associationSet = new AssociationSet("A", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace));

            entityContainer.AddEntitySetBase(associationSet);

            Assert.Equal(1, entityContainer.AssociationSets.Count);

            entityContainer.RemoveEntitySetBase(associationSet);

            Assert.Empty(entityContainer.AssociationSets);
            Assert.Null(associationSet.EntityContainer);
        }
Exemplo n.º 16
0
 public override void VisitEdmAssociationSet(AssociationSet item)
 {
     _schemaWriter.WriteAssociationSetElementHeader(item);
     base.VisitEdmAssociationSet(item);
     if (item.SourceSet != null)
     {
         _schemaWriter.WriteAssociationSetEndElement(item.SourceSet, item.ElementType.SourceEnd.Name);
     }
     if (item.TargetSet != null)
     {
         _schemaWriter.WriteAssociationSetEndElement(item.TargetSet, item.ElementType.TargetEnd.Name);
     }
     _schemaWriter.WriteEndElement();
 }
        /// <summary>
        /// Initializes a new ModificationFunctionMemberPath instance.
        /// </summary>
        /// <param name="members">Gets the members in the path from the leaf (the member being bound)
        /// to the root of the structure.</param>
        /// <param name="associationSet">Gets the association set to which we are navigating 
        /// via this member. If the value is null, this is not a navigation member path.</param>
        public ModificationFunctionMemberPath(IEnumerable<EdmMember> members, AssociationSet associationSet)
        {
            Check.NotNull(members, "members");

            _members = new ReadOnlyCollection<EdmMember>(new List<EdmMember>(members));

            if (null != associationSet)
            {
                Debug.Assert(2 == Members.Count, "Association bindings must always consist of the end and the key");

                // find the association set end
                _associationSetEnd = associationSet.AssociationSetEnds[Members[1].Name];
            }
        }
            public void Create_should_return_only_fk_associations()
            {
                var filter = new ViewgenContext.OneToOneFkAssociationsForEntitiesFilter();

                var associationType1
                    = new AssociationType("A1", EdmConstants.TransientNamespace, true, DataSpace.CSpace);

                var entityType = new EntityType("E", "N", DataSpace.CSpace);

                associationType1.AddMember(
                    new AssociationEndMember("S", entityType)
                        {
                            RelationshipMultiplicity = RelationshipMultiplicity.One
                        });
                associationType1.AddMember(
                    new AssociationEndMember("T", entityType)
                        {
                            RelationshipMultiplicity = RelationshipMultiplicity.One
                        });

                associationType1.SetReadOnly();

                var associationSet1 = new AssociationSet("AS1", associationType1);

                var associationType2
                    = new AssociationType("A2", EdmConstants.TransientNamespace, false, DataSpace.CSpace);

                associationType2.AddMember(
                    new AssociationEndMember("S", entityType)
                        {
                            RelationshipMultiplicity = RelationshipMultiplicity.One
                        });
                associationType2.AddMember(
                    new AssociationEndMember("T", entityType)
                        {
                            RelationshipMultiplicity = RelationshipMultiplicity.One
                        });

                associationType2.SetReadOnly();

                var associationSet2 = new AssociationSet("AS2", associationType2);

                var query
                    = filter.Filter(
                        new[] { entityType },
                        new[] { associationSet1, associationSet2 });

                Assert.Same(associationSet1, query.Single());
            }
        internal StorageAssociationSetMapping(AssociationSet extent, EntitySet entitySet)
            : base(extent, null)
        {
            DebugCheck.NotNull(entitySet);

            var associationTypeMapping
                = new StorageAssociationTypeMapping(extent.ElementType, this);

            var mappingFragment
                = new StorageMappingFragment(entitySet, associationTypeMapping, false);

            associationTypeMapping.AddFragment(mappingFragment);

            AddTypeMapping(associationTypeMapping);
        }
Exemplo n.º 20
0
        private void AppendDropForeignKeys(AssociationSet associationSet)
        {
            var constraint = associationSet.ElementType.ReferentialConstraints.Single();
            var principalEnd = associationSet.AssociationSetEnds[constraint.FromRole.Name];
            var dependentEnd = associationSet.AssociationSetEnds[constraint.ToRole.Name];

            AppendObjectExistenceCheck(QuoteIdentifier(GetSchemaName(dependentEnd.EntitySet)) + "." + QuoteIdentifier(associationSet.Name), "F");
            AppendNewLine();
            AppendSql("alter table ");
            AppendTableName(dependentEnd.EntitySet);
            AppendSql(" drop constraint ");
            AppendIdentifier(associationSet.Name);
            AppendSql(";");
            AppendNewLine();
        }
        public void Can_get_and_set_store_entity_set()
        {
            var entitySet1 = new EntitySet();
            var associationSet = new AssociationSet("AS", new AssociationType());

            var associationSetMapping
                = new StorageAssociationSetMapping(associationSet, entitySet1);

            Assert.Same(entitySet1, associationSetMapping.StoreEntitySet);

            var entitySet2 = new EntitySet();

            associationSetMapping.StoreEntitySet = entitySet2;

            Assert.Same(entitySet2, associationSetMapping.StoreEntitySet);
        }
        public void Can_get_and_set_store_entity_set()
        {
            var entitySet1 = new EntitySet();
            var associationSet = new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace));

            var associationSetMapping
                = new StorageAssociationSetMapping(associationSet, entitySet1);

            Assert.Same(entitySet1, associationSetMapping.StoreEntitySet);

            var entitySet2 = new EntitySet();

            associationSetMapping.StoreEntitySet = entitySet2;

            Assert.Same(entitySet2, associationSetMapping.StoreEntitySet);
        }
Exemplo n.º 23
0
        public ForeignKeyBuilder(EdmModel database, string name)
        {
            Check.NotNull(database, "database");

            _database = database;

            _associationType
                = new AssociationType(
                    name,
                    EdmModelExtensions.DefaultStoreNamespace,
                    true,
                    DataSpace.SSpace);

            _associationSet
                = new AssociationSet(_associationType.Name, _associationType);
        }
Exemplo n.º 24
0
 internal WithRelationship(
     AssociationSet associationSet,
     AssociationEndMember fromEnd,
     EntityType fromEndEntityType,
     AssociationEndMember toEnd,
     EntityType toEndEntityType,
     IEnumerable<MemberPath> toEndEntityKeyMemberPaths)
 {
     m_associationSet = associationSet;
     m_fromEnd = fromEnd;
     m_fromEndEntityType = fromEndEntityType;
     m_toEnd = toEnd;
     m_toEndEntityType = toEndEntityType;
     m_toEndEntitySet = MetadataHelper.GetEntitySetAtEnd(associationSet, toEnd);
     m_toEndEntityKeyMemberPaths = toEndEntityKeyMemberPaths;
 }
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
            var associationSet = new AssociationSet("AS", associationType);
            var associationSetMapping
                = new AssociationSetMapping(
                    associationSet,
                    new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)));
            var associationTypeMapping = new AssociationTypeMapping(associationSetMapping);
            var fragment = new MappingFragment(new EntitySet(), associationTypeMapping, false);
            associationTypeMapping.MappingFragment = fragment;

            Assert.False(fragment.IsReadOnly);
            associationTypeMapping.SetReadOnly();
            Assert.True(fragment.IsReadOnly);
        }
        public void Can_initialize_with_entity_set()
        {
            var entitySet = new EntitySet();
            var associationSet = new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace));

            var associationSetMapping
                = new AssociationSetMapping(associationSet, entitySet);

            var associationTypeMapping = associationSetMapping.TypeMappings.Single();

            Assert.NotNull(associationTypeMapping);
            Assert.Same(associationSet.ElementType, associationTypeMapping.Types.Single());
            Assert.Same(associationSetMapping, associationTypeMapping.SetMapping);

            var mappingFragment = associationTypeMapping.MappingFragments.Single();

            Assert.Same(entitySet, mappingFragment.TableSet);
        }
        public void Can_initialize_with_entity_set()
        {
            var entitySet = new EntitySet();
            var associationSet = new AssociationSet("AS", new AssociationType());

            var associationSetMapping
                = new StorageAssociationSetMapping(associationSet, entitySet);

            var associationTypeMapping = associationSetMapping.TypeMappings.Single();

            Assert.NotNull(associationTypeMapping);
            Assert.Same(associationSet.ElementType, associationTypeMapping.Types.Single());
            Assert.Same(associationSetMapping, associationTypeMapping.SetMapping);

            var mappingFragment = associationTypeMapping.MappingFragments.Single();

            Assert.Same(entitySet, mappingFragment.TableSet);
        }
        // effects: Creates a foreign key constraint of the form:
        // <i_childTable, i_childColumns> --> <i_parentTable, i_childColumns>
        // i_fkeySet is the name of the constraint
        internal ForeignConstraint(
            AssociationSet i_fkeySet, EntitySet i_parentTable, EntitySet i_childTable,
            ReadOnlyMetadataCollection<EdmProperty> i_parentColumns, ReadOnlyMetadataCollection<EdmProperty> i_childColumns)
        {
            m_fKeySet = i_fkeySet;
            m_parentTable = i_parentTable;
            m_childTable = i_childTable;
            m_childColumns = new List<MemberPath>();
            // Create parent and child paths using the table names
            foreach (var property in i_childColumns)
            {
                var path = new MemberPath(m_childTable, property);
                m_childColumns.Add(path);
            }

            m_parentColumns = new List<MemberPath>();
            foreach (var property in i_parentColumns)
            {
                var path = new MemberPath(m_parentTable, property);
                m_parentColumns.Add(path);
            }
        }
        public void Can_get_association_ends_from_association_set()
        {
            var sourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            var targetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));

            var associationType
                = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);

            associationType.AddKeyMember(targetEnd);
            associationType.AddKeyMember(sourceEnd);

            var associationSet = new AssociationSet("A", associationType);

            Assert.Null(associationSet.SourceEnd);
            Assert.Null(associationSet.TargetEnd);

            associationSet.AddAssociationSetEnd(new AssociationSetEnd(new EntitySet(), associationSet, sourceEnd));
            associationSet.AddAssociationSetEnd(new AssociationSetEnd(new EntitySet(), associationSet, targetEnd));

            Assert.Same(sourceEnd, associationSet.SourceEnd);
            Assert.Same(targetEnd, associationSet.TargetEnd);
        }
        public void Can_get_and_set_source__and_target_end_mappings()
        {
            var entitySet1 = new EntitySet();
            var associationSet = new AssociationSet("AS", new AssociationType());

            var associationSetMapping
                = new StorageAssociationSetMapping(associationSet, entitySet1);

            Assert.Null(associationSetMapping.SourceEndMapping);
            Assert.Null(associationSetMapping.TargetEndMapping);

            var sourceEndMapping = new StorageEndPropertyMapping(new EdmProperty("P"));

            associationSetMapping.SourceEndMapping = sourceEndMapping;

            Assert.Same(sourceEndMapping, associationSetMapping.SourceEndMapping);

            var targetEndMapping = new StorageEndPropertyMapping(new EdmProperty("P"));

            associationSetMapping.TargetEndMapping = targetEndMapping;

            Assert.Same(targetEndMapping, associationSetMapping.TargetEndMapping);
        }
        /// <summary>
        /// Creates a read-only AssociationSet instance from the specified parameters.
        /// </summary>
        /// <param name="name">The name of the association set.</param>
        /// <param name="type">The association type of the elements in the association set.</param>
        /// <param name="sourceSet">The entity set for the source association set end.</param>
        /// <param name="targetSet">The entity set for the target association set end.</param>
        /// <param name="metadataProperties">Metadata properties to be associated with the instance.</param>
        /// <returns>The newly created AssociationSet instance.</returns>
        /// <exception cref="T:System.ArgumentException">The specified name is null or empty.</exception>
        /// <exception cref="T:System.ArgumentNullException">The specified association type is null.</exception>
        /// <exception cref="T:System.ArgumentException">
        /// The entity type of one of the ends of the specified
        /// association type does not match the entity type of the corresponding entity set end.
        /// </exception>
        public static AssociationSet Create(
            string name,
            AssociationType type,
            EntitySet sourceSet,
            EntitySet targetSet,
            IEnumerable <MetadataProperty> metadataProperties)
        {
            Check.NotEmpty(name, nameof(name));
            Check.NotNull <AssociationType>(type, nameof(type));
            if (!AssociationSet.CheckEntitySetAgainstEndMember(sourceSet, type.SourceEnd) || !AssociationSet.CheckEntitySetAgainstEndMember(targetSet, type.TargetEnd))
            {
                throw new ArgumentException(Strings.AssociationSet_EndEntityTypeMismatch);
            }
            AssociationSet associationSet = new AssociationSet(name, type);

            if (sourceSet != null)
            {
                associationSet.SourceSet = sourceSet;
            }
            if (targetSet != null)
            {
                associationSet.TargetSet = targetSet;
            }
            if (metadataProperties != null)
            {
                associationSet.AddMetadataProperties(metadataProperties.ToList <MetadataProperty>());
            }
            associationSet.SetReadOnly();
            return(associationSet);
        }
Exemplo n.º 32
0
        public void Create_checks_each_EntitySet_parameter_against_corresponding_AssociationEndMember()
        {
            var source    = new EntityType("Source", "Namespace", DataSpace.CSpace);
            var target    = new EntityType("Target", "Namespace", DataSpace.CSpace);
            var other     = new EntityType("Other", "Namespace", DataSpace.CSpace);
            var sourceSet = new EntitySet("SourceSet", "Schema", "Table", "Query", source);
            var targetSet = new EntitySet("TargetSet", "Schema", "Table", "Query", target);
            var otherSet  = new EntitySet("OtherSet", "Schema", "Table", "Query", other);
            var sourceEnd = new AssociationEndMember("SourceEnd", source);
            var targetEnd = new AssociationEndMember("TargetEnd", target);

            var associationTypeWithNonNullEndMembers =
                AssociationType.Create(
                    "AssociationType",
                    "Namespace",
                    true,
                    DataSpace.CSpace,
                    sourceEnd,
                    targetEnd,
                    null,
                    null);

            var associationTypeWithNullEndMembers =
                AssociationType.Create(
                    "AssociationType",
                    "Namespace",
                    true,
                    DataSpace.CSpace,
                    null, // sourceEnd
                    null, // targetEnd
                    null,
                    null);

            Assert.NotNull(
                AssociationSet.Create(
                    "AssociationSet",
                    associationTypeWithNonNullEndMembers,
                    sourceSet,
                    targetSet,
                    null));

            Assert.NotNull(
                AssociationSet.Create(
                    "AssociationSet",
                    associationTypeWithNullEndMembers,
                    null, // sourceSet
                    null, // targetSet
                    null));

            Assert.Equal(
                Resources.Strings.AssociationSet_EndEntityTypeMismatch,
                Assert.Throws <ArgumentException>(
                    () => AssociationSet.Create(
                        "AssociationSet",
                        associationTypeWithNonNullEndMembers,
                        otherSet,
                        targetSet,
                        null)).Message);

            Assert.Equal(
                Resources.Strings.AssociationSet_EndEntityTypeMismatch,
                Assert.Throws <ArgumentException>(
                    () => AssociationSet.Create(
                        "AssociationSet",
                        associationTypeWithNonNullEndMembers,
                        sourceSet,
                        otherSet,
                        null)).Message);

            Assert.Equal(
                Resources.Strings.AssociationSet_EndEntityTypeMismatch,
                Assert.Throws <ArgumentException>(
                    () => AssociationSet.Create(
                        "AssociationSet",
                        associationTypeWithNonNullEndMembers,
                        null, // sourceSet
                        targetSet,
                        null)).Message);

            Assert.Equal(
                Resources.Strings.AssociationSet_EndEntityTypeMismatch,
                Assert.Throws <ArgumentException>(
                    () => AssociationSet.Create(
                        "AssociationSet",
                        associationTypeWithNonNullEndMembers,
                        sourceSet,
                        null, // targetSet
                        null)).Message);

            Assert.Equal(
                Resources.Strings.AssociationSet_EndEntityTypeMismatch,
                Assert.Throws <ArgumentException>(
                    () => AssociationSet.Create(
                        "AssociationSet",
                        associationTypeWithNullEndMembers,
                        null, // sourceSet
                        targetSet,
                        null)).Message);

            Assert.Equal(
                Resources.Strings.AssociationSet_EndEntityTypeMismatch,
                Assert.Throws <ArgumentException>(
                    () => AssociationSet.Create(
                        "AssociationSet",
                        associationTypeWithNullEndMembers,
                        sourceSet,
                        null, // targetSet
                        null)).Message);
        }
Exemplo n.º 33
0
        public void WriteAssociationSetMapping_should_write_modification_function_mapping()
        {
            var fixture = new Fixture();

            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var entitySet  = new EntitySet("ES", "S", null, null, entityType);

            new EntityContainer("EC", DataSpace.SSpace).AddEntitySetBase(entitySet);
            var associationSet = new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace));

            var associationEndMember1 = new AssociationEndMember("Source", new EntityType("E", "N", DataSpace.CSpace));

            associationSet.AddAssociationSetEnd(new AssociationSetEnd(entitySet, associationSet, associationEndMember1));

            var associationEndMember2 = new AssociationEndMember("Target", new EntityType("E", "N", DataSpace.CSpace));

            associationSet.AddAssociationSetEnd(new AssociationSetEnd(entitySet, associationSet, associationEndMember2));

            var storageModificationFunctionMapping
                = new ModificationFunctionMapping(
                      associationSet,
                      associationSet.ElementType,
                      new EdmFunction("F", "N", DataSpace.SSpace, new EdmFunctionPayload()),
                      new[]
            {
                new ModificationFunctionParameterBinding(
                    new FunctionParameter(
                        "P",
                        TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)),
                        ParameterMode.In),
                    new ModificationFunctionMemberPath(
                        new EdmMember[]
                {
                    new EdmProperty("K"),
                    associationEndMember1
                },
                        associationSet),
                    true),
                new ModificationFunctionParameterBinding(
                    new FunctionParameter(
                        "P",
                        TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)),
                        ParameterMode.In),
                    new ModificationFunctionMemberPath(
                        new EdmMember[]
                {
                    new EdmProperty("K"),
                    associationEndMember2
                },
                        associationSet),
                    false)
            },
                      null,
                      null);

            var associationSetMapping
                = new AssociationSetMapping(
                      associationSet,
                      entitySet)
                {
                SourceEndMapping
                    = new EndPropertyMapping
                    {
                    AssociationEnd = associationEndMember1
                    },
                TargetEndMapping
                    = new EndPropertyMapping
                    {
                    AssociationEnd = associationEndMember2
                    },
                ModificationFunctionMapping = new AssociationSetModificationFunctionMapping(
                    associationSet,
                    storageModificationFunctionMapping,
                    storageModificationFunctionMapping)
                };

            fixture.Writer.WriteAssociationSetMappingElement(associationSetMapping);

            Assert.Equal(
                @"<AssociationSetMapping Name=""AS"" TypeName="".A"" StoreEntitySet=""E"">
  <EndProperty Name=""Source"" />
  <EndProperty Name=""Target"" />
  <ModificationFunctionMapping>
    <InsertFunction FunctionName=""N.F"">
      <EndProperty Name=""Source"">
        <ScalarProperty Name=""K"" ParameterName=""P"" Version=""Current"" />
      </EndProperty>
      <EndProperty Name=""Target"">
        <ScalarProperty Name=""K"" ParameterName=""P"" Version=""Original"" />
      </EndProperty>
    </InsertFunction>
    <DeleteFunction FunctionName=""N.F"">
      <EndProperty Name=""Source"">
        <ScalarProperty Name=""K"" ParameterName=""P"" Version=""Current"" />
      </EndProperty>
      <EndProperty Name=""Target"">
        <ScalarProperty Name=""K"" ParameterName=""P"" Version=""Original"" />
      </EndProperty>
    </DeleteFunction>
  </ModificationFunctionMapping>
</AssociationSetMapping>",
                fixture.ToString());
        }
Exemplo n.º 34
0
 // <summary>
 // Initializes a new instance of AssocationSetEnd
 // </summary>
 // <param name="entitySet"> Entity set that this end refers to </param>
 // <param name="parentSet"> The association set which this belongs to </param>
 // <param name="endMember"> The end member of the association set which this is an instance of </param>
 // <exception cref="System.ArgumentNullException">Thrown if either the role,entitySet, parentSet or endMember arguments are null</exception>
 internal AssociationSetEnd(EntitySet entitySet, AssociationSet parentSet, AssociationEndMember endMember)
 {
     _entitySet = Check.NotNull(entitySet, "entitySet");
     _parentSet = Check.NotNull(parentSet, "parentSet");
     _endMember = Check.NotNull(endMember, "endMember");
 }