예제 #1
0
 /// <summary>
 /// Get the key for the given association end.
 /// </summary>
 /// <param name="end">associated end whose key needs to be reduced.</param>
 /// <returns>key for the given association end.</returns>
 private string GetAssociationKey(ResourceAssociationSetEnd end)
 {
     return
         (end.ResourceSet.Name + "_" +
          end.ResourceType.FullName + "_" +
          (end.ResourceProperty == null ? String.Empty : end.ResourceProperty.Name));
 }
예제 #2
0
        private ResourceAssociationSet GetCreateAssociationSet(
            MetadataWorkspace workspace,
            AssociationSet edmAssocSet)
        {
            ResourceAssociationSet resourceAssocSet;

            if (associationSets.TryGetValue(edmAssocSet.Name, out resourceAssocSet) == false)
            {
                ResourceAssociationSetEnd rse1 = CreateResourceAssociationSetEnd(
                    workspace, edmAssocSet.AssociationSetEnds[0]);
                ResourceAssociationSetEnd rse2 = CreateResourceAssociationSetEnd(
                    workspace, edmAssocSet.AssociationSetEnds[1]);

                resourceAssocSet = new ResourceAssociationSet(edmAssocSet.Name, rse1, rse2);

                associationSets.Add(edmAssocSet.Name, resourceAssocSet);

                ResourceAssociationTypeEnd rst1 = CreateResourceAssociationTypeEnd(
                    workspace, edmAssocSet.AssociationSetEnds[0]);
                ResourceAssociationTypeEnd rst2 = CreateResourceAssociationTypeEnd(
                    workspace, edmAssocSet.AssociationSetEnds[1]);

                ResourceAssociationType resourceAssocType = new ResourceAssociationType(
                    edmAssocSet.ElementType.Name,
                    edmAssocSet.ElementType.NamespaceName, rst1, rst2);

                resourceAssocSet.ResourceAssociationType = resourceAssocType;
            }

            return(resourceAssocSet);
        }
예제 #3
0
        public ResourceAssociationSet GetResourceAssociationSet(
            ResourceSet resourceSet,
            ResourceType resourceType,
            ResourceProperty resourceProperty)
        {
            if (resourceSet == null)
            {
                throw new ArgumentException("The specified resource set is null.");
            }
            if (resourceType == null)
            {
                throw new ArgumentException("The specified resource type is null.");
            }
            if (resourceProperty == null)
            {
                throw new ArgumentException("The specified resource property is null.");
            }


            ResourceType targetResourceType = resourceProperty.ResourceType;
            ResourceSet  targetResourceSet  = this.ResourceSets.
                                              Where(rs => rs.ResourceType.InstanceType.IsAssignableFrom(targetResourceType.InstanceType)).Single();

            string associationName = resourceType.Name + '_' + resourceProperty.Name;
            ResourceAssociationSetEnd sourceEnd = new ResourceAssociationSetEnd(resourceSet, resourceType, resourceProperty);
            ResourceAssociationSetEnd targetEnd = new ResourceAssociationSetEnd(targetResourceSet, targetResourceType, null);

            return(new ResourceAssociationSet(associationName, sourceEnd, targetEnd));
        }
예제 #4
0
        public void InvalidCasesTest()
        {
            ResourceProperty id = new ResourceProperty("ID", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, ResourceType.GetPrimitiveResourceType(typeof(int)))
            {
                CanReflectOnInstanceTypeProperty = false
            };
            ResourceType customerType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Foo", "CustomerType", false);

            customerType.AddProperty(id);
            ResourceType orderType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Foo", "OrderType", false);

            orderType.AddProperty(id);

            ResourceProperty customerOrders = new ResourceProperty("Orders", ResourcePropertyKind.ResourceSetReference, orderType);
            ResourceProperty orderCustomer  = new ResourceProperty("Customer", ResourcePropertyKind.ResourceReference, customerType);

            customerType.AddProperty(customerOrders);
            orderType.AddProperty(orderCustomer);
            customerOrders.CanReflectOnInstanceTypeProperty = false;
            orderCustomer.CanReflectOnInstanceTypeProperty  = false;
            customerType.SetReadOnly();
            orderType.SetReadOnly();

            ResourceSet customerSet = new ResourceSet("Customers", customerType);
            ResourceSet orderSet    = new ResourceSet("Orders", orderType);

            ResourceAssociationSetEnd end1 = new ResourceAssociationSetEnd(customerSet, customerType, null);
            ResourceAssociationSetEnd end2 = new ResourceAssociationSetEnd(orderSet, orderType, null);

            ExceptionUtils.CheckInvalidConstructorParameters(
                typeof(ResourceAssociationSet),
                "Value cannot be null or empty.\r\nParameter name: name",
                null, end1, end2);
            ExceptionUtils.CheckInvalidConstructorParameters(
                typeof(ResourceAssociationSet),
                "Value cannot be null or empty.\r\nParameter name: name",
                string.Empty, end1, end2);
            ExceptionUtils.CheckInvalidConstructorParameters(
                typeof(ResourceAssociationSet),
                "Value cannot be null.\r\nParameter name: end1",
                "Customer_Order", null, end2);
            ExceptionUtils.CheckInvalidConstructorParameters(
                typeof(ResourceAssociationSet),
                "Value cannot be null.\r\nParameter name: end2",
                "Customer_Order", end1, null);
            ExceptionUtils.CheckInvalidConstructorParameters(
                typeof(ResourceAssociationSet),
                "The ResourceProperty of the ResourceAssociationEnds cannot both be null.",
                "Customer_Order", end1, end2);
        }