コード例 #1
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);
        }
コード例 #2
0
        public ResourceAssociationSet GetResourceAssociationSet(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty)
        {
            ResourceAssociationSet resourceAssociationSet;

            if (resourceSet == null || resourceType == null)
            {
                return(null);
            }
            else
            {
                if (resourceType.Properties.Contains(resourceProperty))
                {
                    Microsoft.Management.Odata.Schema.Schema.AssociationType associationType = (resourceProperty.GetCustomState() as ReferenceCustomState).AssociationType;
                    if (associationType != null)
                    {
                        List <ResourceAssociationSet> .Enumerator enumerator = associationType.WcfClass.GetEnumerator();
                        try
                        {
                            while (enumerator.MoveNext())
                            {
                                ResourceAssociationSet current = enumerator.Current;
                                if (current.End1.ResourceSet != resourceSet || current.End1.ResourceType != resourceType || current.End1.ResourceProperty != resourceProperty)
                                {
                                    if (current.End2.ResourceSet != resourceSet || current.End2.ResourceType != resourceType || current.End2.ResourceProperty != resourceProperty)
                                    {
                                        continue;
                                    }
                                    resourceAssociationSet = current;
                                    return(resourceAssociationSet);
                                }
                                else
                                {
                                    resourceAssociationSet = current;
                                    return(resourceAssociationSet);
                                }
                            }
                            return(null);
                        }
                        finally
                        {
                            enumerator.Dispose();
                        }
                        return(resourceAssociationSet);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
        }
コード例 #3
0
        ResourceAssociationSet IDataServiceMetadataProvider.GetResourceAssociationSet(
            ResourceSet resourceSet,
            ResourceType resourceType,
            ResourceProperty resourceProperty)
        {
            // We have the resource association set precreated on the property annotation,
            // so no need to compute anything in here
            ResourceAssociationSet resourceAssociationSet = resourceProperty.GetAnnotation().ResourceAssociationSet;

            return(resourceAssociationSet);
        }
コード例 #4
0
        /// <summary>
        /// Gets the ResourceAssociationSet instance when given the source association end.
        /// </summary>
        /// <param name="resourceSet">Resource set of the source association end.</param>
        /// <param name="resourceType">Resource type of the source association end.</param>
        /// <param name="resourceProperty">Resource property of the source association end.</param>
        /// <returns>ResourceAssociationSet instance.</returns>
        /// <remarks>This method returns a ResourceAssociationSet representing a reference which is specified
        /// by the <paramref name="resourceProperty"/> on the <paramref name="resourceType"/> for instances in the <paramref name="resourceSet"/>.</remarks>
        public ResourceAssociationSet GetResourceAssociationSet(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty)
        {
            // We have the resource association set precreated on the property annotation, so no need to compute anything in here
            ResourceAssociationSet resourceAssociationSet = resourceProperty.GetAnnotation().ResourceAssociationSet;

            // Just few verification to show what is expected of the returned resource association set.
            Debug.Assert(resourceAssociationSet.End1.ResourceSet == resourceSet, "The precreated resource association set doesn't match the specified resource set.");
            Debug.Assert(resourceAssociationSet.End1.ResourceType == resourceType, "The precreated resource association set doesn't match the specified resource type.");
            Debug.Assert(resourceAssociationSet.End1.ResourceProperty == resourceProperty, "The precreated resource association set doesn't match its resource property.");

            return(resourceAssociationSet);
        }
コード例 #5
0
ファイル: DSPMetadata.cs プロジェクト: zhonli/odata.net
        /// <summary>
        /// Add the given association set.
        /// </summary>
        /// <param name="associationSet">association set to be added.</param>
        public void AddResourceAssociationSet(ResourceAssociationSet associationSet)
        {
            if (associationSet.End1.ResourceProperty != null)
            {
                this.associationSets.Add(GetAssociationKey(associationSet.End1), associationSet);
            }

            if (associationSet.End2.ResourceProperty != null)
            {
                this.associationSets.Add(GetAssociationKey(associationSet.End2), associationSet);
            }
        }
コード例 #6
0
 private static bool HasAssociationEndOf(
     ResourceAssociationSet set,
     ResourceSet resourceSet,
     ResourceType resourceType,
     ResourceProperty resourceProperty)
 {
     return((set.End1.ResourceSet == resourceSet &&
             set.End1.ResourceType == resourceType &&
             set.End1.ResourceProperty == resourceProperty) ||
            (set.End2.ResourceSet == resourceSet &&
             set.End2.ResourceType == resourceType &&
             set.End2.ResourceProperty == resourceProperty));
 }
コード例 #7
0
            public void CreateWcfType(Dictionary <string, ResourceSet> allSets)
            {
                ResourceType type         = this.Ends[0].Type;
                ResourceType resourceType = this.Ends[1].Type;

                char[] chrArray = new char[1];
                chrArray[0] = '.';
                string[]    strArrays    = this.Name.Split(chrArray);
                string      str          = strArrays[(int)strArrays.Length - 1];
                ResourceSet resourceSet  = allSets.Values.FirstOrDefault <ResourceSet>((ResourceSet it) => it.ResourceType == type);
                ResourceSet resourceSet1 = allSets.Values.FirstOrDefault <ResourceSet>((ResourceSet it) => it.ResourceType == resourceType);

                if (resourceSet == null)
                {
                    foreach (ResourceSet value in allSets.Values)
                    {
                        if (!type.IsSameOrBaseType(value.ResourceType))
                        {
                            continue;
                        }
                        resourceSet = value;
                        break;
                    }
                }
                if (resourceSet1 == null)
                {
                    foreach (ResourceSet value1 in allSets.Values)
                    {
                        if (!resourceType.IsSameOrBaseType(value1.ResourceType))
                        {
                            continue;
                        }
                        resourceSet1 = value1;
                        break;
                    }
                }
                if (resourceSet != null && resourceSet1 != null)
                {
                    ResourceAssociationSet resourceAssociationSet = new ResourceAssociationSet(str, new ResourceAssociationSetEnd(resourceSet, type, this.Ends[0].Property), new ResourceAssociationSetEnd(resourceSet1, resourceType, this.Ends[1].Property));
                    this.WcfClass.Add(resourceAssociationSet);
                }
            }
コード例 #8
0
        /// <summary>
        /// Lazy get the association set for specified navigation property.
        /// </summary>
        public ResourceAssociationSet LazyGetResourceAssociationSet(
            TContext adapter,
            ResourceSet resourceSet,
            ResourceType resourceType,
            ResourceProperty resourceProperty)
        {
            if (IsNavigationProperty(resourceProperty) == false)
            {
                throw new ArgumentException(
                          string.Format("Property '{0}' is not a navigation property.",
                                        resourceProperty.Name),
                          "resourceProperty");
            }

            Initialize(adapter);

            ResourceAssociationSet resourceAssocSet =
                associationSets.Values
                .Where(x => HasAssociationEndOf(x, resourceSet, resourceType, resourceProperty))
                .First();

            return(resourceAssocSet);
        }
コード例 #9
0
 public void AddResourceAssociationSet(ResourceAssociationSet associationSet)
 {
     this.resourceAssociationSets.Add(associationSet);
 }
コード例 #10
0
        public DefaultContainer_Metadata()
        {
            // ComplexTypes declared here

            Microsoft.Test.OData.Framework.TestProviders.Common.LazyResourceType contactdetails_ComplexType = new Microsoft.Test.OData.Framework.TestProviders.Common.LazyResourceType(typeof(Microsoft.Test.OData.Framework.TestProviders.Dictionary.ResourceInstance), ResourceTypeKind.ComplexType, null, "Microsoft.Test.OData.Services.OpenTypesService", "ContactDetails", false);
            contactdetails_ComplexType.IsOpenType = false;
            contactdetails_ComplexType.CanReflectOnInstanceType = false;
            this.ResourceTypes.Add(contactdetails_ComplexType);

            // ComplexTypes properties declared

            ResourceProperty contactdetails_FirstContacted = new ResourceProperty("FirstContacted", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(byte[])));

            contactdetails_FirstContacted.CanReflectOnInstanceTypeProperty = false;
            contactdetails_ComplexType.AddLazyProperty(contactdetails_FirstContacted);
            ResourceProperty contactdetails_LastContacted = new ResourceProperty("LastContacted", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(System.DateTimeOffset)));

            contactdetails_LastContacted.CanReflectOnInstanceTypeProperty = false;
            contactdetails_ComplexType.AddLazyProperty(contactdetails_LastContacted);
            ResourceProperty contactdetails_Contacted = new ResourceProperty("Contacted", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(System.DateTimeOffset)));

            contactdetails_Contacted.CanReflectOnInstanceTypeProperty = false;
            contactdetails_ComplexType.AddLazyProperty(contactdetails_Contacted);
            ResourceProperty contactdetails_GUID = new ResourceProperty("GUID", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(System.Guid)));

            contactdetails_GUID.CanReflectOnInstanceTypeProperty = false;
            contactdetails_ComplexType.AddLazyProperty(contactdetails_GUID);
            ResourceProperty contactdetails_PreferedContactTime = new ResourceProperty("PreferedContactTime", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(System.TimeSpan)));

            contactdetails_PreferedContactTime.CanReflectOnInstanceTypeProperty = false;
            contactdetails_ComplexType.AddLazyProperty(contactdetails_PreferedContactTime);
            ResourceProperty contactdetails_Byte = new ResourceProperty("Byte", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(byte)));

            contactdetails_Byte.CanReflectOnInstanceTypeProperty = false;
            contactdetails_ComplexType.AddLazyProperty(contactdetails_Byte);
            ResourceProperty contactdetails_SignedByte = new ResourceProperty("SignedByte", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(sbyte)));

            contactdetails_SignedByte.CanReflectOnInstanceTypeProperty = false;
            contactdetails_ComplexType.AddLazyProperty(contactdetails_SignedByte);
            ResourceProperty contactdetails_Double = new ResourceProperty("Double", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(double)));

            contactdetails_Double.CanReflectOnInstanceTypeProperty = false;
            contactdetails_ComplexType.AddLazyProperty(contactdetails_Double);
            ResourceProperty contactdetails_Single = new ResourceProperty("Single", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(float)));

            contactdetails_Single.CanReflectOnInstanceTypeProperty = false;
            contactdetails_ComplexType.AddLazyProperty(contactdetails_Single);
            ResourceProperty contactdetails_Short = new ResourceProperty("Short", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(short)));

            contactdetails_Short.CanReflectOnInstanceTypeProperty = false;
            contactdetails_ComplexType.AddLazyProperty(contactdetails_Short);
            ResourceProperty contactdetails_Int = new ResourceProperty("Int", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int)));

            contactdetails_Int.CanReflectOnInstanceTypeProperty = false;
            contactdetails_ComplexType.AddLazyProperty(contactdetails_Int);
            ResourceProperty contactdetails_Long = new ResourceProperty("Long", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(long)));

            contactdetails_Long.CanReflectOnInstanceTypeProperty = false;
            contactdetails_ComplexType.AddLazyProperty(contactdetails_Long);

            // EntityTypes declared here

            Microsoft.Test.OData.Framework.TestProviders.Common.LazyResourceType row_EntityType = new Microsoft.Test.OData.Framework.TestProviders.Common.LazyResourceType(typeof(Microsoft.Test.OData.Framework.TestProviders.Dictionary.ResourceInstance), ResourceTypeKind.EntityType, null, "Microsoft.Test.OData.Services.OpenTypesService", "Row", false);
            row_EntityType.IsOpenType = true;
            row_EntityType.CanReflectOnInstanceType = false;
            this.ResourceTypes.Add(row_EntityType);

            Microsoft.Test.OData.Framework.TestProviders.Common.LazyResourceType indexedrow_EntityType = new Microsoft.Test.OData.Framework.TestProviders.Common.LazyResourceType(typeof(Microsoft.Test.OData.Framework.TestProviders.Dictionary.ResourceInstance), ResourceTypeKind.EntityType, row_EntityType, "Microsoft.Test.OData.Services.OpenTypesService", "IndexedRow", false);
            indexedrow_EntityType.IsOpenType = true;
            indexedrow_EntityType.CanReflectOnInstanceType = false;
            this.ResourceTypes.Add(indexedrow_EntityType);

            Microsoft.Test.OData.Framework.TestProviders.Common.LazyResourceType rowindex_EntityType = new Microsoft.Test.OData.Framework.TestProviders.Common.LazyResourceType(typeof(Microsoft.Test.OData.Framework.TestProviders.Dictionary.ResourceInstance), ResourceTypeKind.EntityType, null, "Microsoft.Test.OData.Services.OpenTypesService", "RowIndex", false);
            rowindex_EntityType.IsOpenType = true;
            rowindex_EntityType.CanReflectOnInstanceType = false;
            this.ResourceTypes.Add(rowindex_EntityType);

            // EntityType primitive and complexType properties declared here

            ResourceProperty row_Id = new ResourceProperty("Id", (ResourcePropertyKind.Primitive | ResourcePropertyKind.Key), ResourceType.GetPrimitiveResourceType(typeof(System.Guid)));

            row_Id.CanReflectOnInstanceTypeProperty = false;
            row_EntityType.AddLazyProperty(row_Id);


            ResourceProperty rowindex_Id = new ResourceProperty("Id", (ResourcePropertyKind.Primitive | ResourcePropertyKind.Key), ResourceType.GetPrimitiveResourceType(typeof(int)));

            rowindex_Id.CanReflectOnInstanceTypeProperty = false;
            rowindex_EntityType.AddLazyProperty(rowindex_Id);

            // EntityTypes navigation properties declared here



            ResourceProperty rowindex_Rows = new ResourceProperty("Rows", ResourcePropertyKind.ResourceSetReference, indexedrow_EntityType);

            rowindex_Rows.CanReflectOnInstanceTypeProperty = false;
            rowindex_EntityType.AddLazyProperty(rowindex_Rows);
            // Add EntitySet Declarations

            var row_EntitySet = new ResourceSet("Row", row_EntityType);

            this.ResourceSets.Add(row_EntitySet);

            var rowindex_EntitySet = new ResourceSet("RowIndex", rowindex_EntityType);

            this.ResourceSets.Add(rowindex_EntitySet);

            // Add AssociationSet Declarations

            Microsoft.OData.Service.Providers.ResourceAssociationSet index_rows_AssociationSet = new ResourceAssociationSet("Index_Rows", new ResourceAssociationSetEnd(rowindex_EntitySet, rowindex_EntityType, rowindex_Rows), new ResourceAssociationSetEnd(row_EntitySet, indexedrow_EntityType, null));
            this.ResourceAssociationSets.Add(index_rows_AssociationSet);
            // ServiceOperations declared here

            row_EntitySet.SetReadOnly();
            rowindex_EntitySet.SetReadOnly();

            row_EntityType.SetReadOnly();
            indexedrow_EntityType.SetReadOnly();
            rowindex_EntityType.SetReadOnly();

            contactdetails_ComplexType.SetReadOnly();
        }
コード例 #11
0
 public void AddAssociationSet(ResourceAssociationSet associationSet)
 {
     _associationSets.Add(associationSet);
 }
コード例 #12
0
    public ODataServiceMetadataProvider GetMetadataProvider(Type dataSourceType)
    {
        ODataServiceMetadataProvider metadata = new ODataServiceMetadataProvider();
        ResourceType customer = new ResourceType(
            typeof(Customer),
            ResourceTypeKind.EntityType,
            null,
            "MyNamespace",
            "Customer",
            false
            );
        ResourceProperty customerCustomerID = new ResourceProperty(
            "CustomerID",
            ResourcePropertyKind.Key |
            ResourcePropertyKind.Primitive,
            ResourceType.GetPrimitiveResourceType(typeof(Guid))
            );

        customer.AddProperty(customerCustomerID);
        ResourceProperty customerCustomerName = new ResourceProperty(
            "CustomerName",
            ResourcePropertyKind.Primitive,
            ResourceType.GetPrimitiveResourceType(typeof(string))
            );

        customer.AddProperty(customerCustomerName);
        ResourceType residentialCustomer = new ResourceType(
            typeof(ResidentialCustomer),
            ResourceTypeKind.EntityType,
            customer,
            "MyNamespace",
            "ResidentialCustomer",
            false
            );
        ResourceType user = new ResourceType(
            typeof(User),
            ResourceTypeKind.EntityType,
            null,
            "MyNamespace",
            "User",
            false
            );
        ResourceProperty userUserID = new ResourceProperty(
            "UserID",
            ResourcePropertyKind.Key |
            ResourcePropertyKind.Primitive,
            ResourceType.GetPrimitiveResourceType(typeof(Guid))
            );

        user.AddProperty(userUserID);
        ResourceProperty userCustomerID = new ResourceProperty(
            "CustomerID",
            ResourcePropertyKind.Primitive,
            ResourceType.GetPrimitiveResourceType(typeof(Guid))
            );

        user.AddProperty(userCustomerID);
        ResourceProperty userEmailAddress = new ResourceProperty(
            "EmailAddress",
            ResourcePropertyKind.Primitive,
            ResourceType.GetPrimitiveResourceType(typeof(string))
            );

        user.AddProperty(userEmailAddress);
        var customerSet            = new ResourceSet("Customers", customer);
        var residentialCustomerSet = new ResourceSet("ResidentialCustomers", residentialCustomer);
        var userSet      = new ResourceSet("Users", user);
        var userCustomer = new ResourceProperty(
            "Customer",
            ResourcePropertyKind.ResourceReference,
            customer
            );

        user.AddProperty(userCustomer);

        var customerUserList = new ResourceProperty(
            "UserList",
            ResourcePropertyKind.ResourceSetReference,
            user
            );

        customer.AddProperty(customerUserList);

        metadata.AddResourceType(customer);
        metadata.AddResourceSet(customerSet);
        metadata.AddResourceType(residentialCustomer);
        metadata.AddResourceSet(residentialCustomerSet);
        metadata.AddResourceType(user);
        metadata.AddResourceSet(userSet);

        ResourceAssociationSet customerUserListSet = new ResourceAssociationSet(
            "CustomerUserList",
            new ResourceAssociationSetEnd(
                customerSet,
                customer,
                customerUserList
                ),
            new ResourceAssociationSetEnd(
                userSet,
                user,
                userCustomer
                )
            );

        customerUserList.CustomState = customerUserListSet;
        userCustomer.CustomState     = customerUserListSet;
        metadata.AddAssociationSet(customerUserListSet);

        return(metadata);
    }
コード例 #13
0
        private static DataServiceMetadataProvider GetMetadataProvider(Type dataSourceType)
        {
            if (_mdprovider != null)
            {
                return(_mdprovider);
            }

            var exposedTypes    = GetExposedTypes(dataSourceType);
            var collectionNames = GetCollectionNames(dataSourceType);
            var mdprovider      = new DataServiceMetadataProvider(collectionNames);
            var resourceTypes   = new Dictionary <string, ResourceType>();

            foreach (var exposedType in exposedTypes)
            {
                // create type
                var odataType = new ResourceType(exposedType, ResourceTypeKind.EntityType, null, "BrightstarEntities",
                                                 NormaliseName(exposedType.Name), false);
                resourceTypes.Add(NormaliseName(exposedType.Name), odataType);

                // create primitive properties
                foreach (var propertyInfo in exposedType.GetProperties())
                {
                    var name = propertyInfo.Name;
                    if (!propertyInfo.PropertyType.IsGenericType && IsLiteral(propertyInfo))
                    {
                        if (propertyInfo.Name.ToLower().Equals("id"))
                        {
                            var idProperty = new ResourceProperty(
                                propertyInfo.Name,
                                ResourcePropertyKind.Key |
                                ResourcePropertyKind.Primitive,
                                ResourceType.GetPrimitiveResourceType(typeof(string))
                                );
                            odataType.AddProperty(idProperty);
                        }
                        else
                        {
                            var valueProperty = new ResourceProperty(
                                propertyInfo.Name,
                                ResourcePropertyKind.Primitive,
                                ResourceType.GetPrimitiveResourceType(propertyInfo.PropertyType)
                                );
                            odataType.AddProperty(valueProperty);
                        }
                    }
                    else
                    {
                        if (IsNullableLiteral(propertyInfo))
                        {
                            var valueProperty = new ResourceProperty(
                                propertyInfo.Name,
                                ResourcePropertyKind.Primitive,
                                ResourceType.GetPrimitiveResourceType(propertyInfo.PropertyType)
                                );
                            odataType.AddProperty(valueProperty);
                        }
                    }
                }
            }

            // make resource sets
            var resourceSets = new Dictionary <string, ResourceSet>();

            foreach (var resourceType in resourceTypes.Values)
            {
                resourceSets.Add(resourceType.Name, new ResourceSet(resourceType.Name, resourceType));
            }

            var associationSets = new Dictionary <string, ResourceAssociationSet>();

            foreach (var exposedType in exposedTypes)
            {
                foreach (var propertyInfo in exposedType.GetProperties())
                {
                    // ignore inverse properties as they get sorted out later.
                    if (IsInverseProperty(propertyInfo))
                    {
                        continue;
                    }

                    if (propertyInfo.PropertyType.IsGenericType && propertyInfo.PropertyType.Name.StartsWith("ICollection"))
                    {
                        var referencedType = propertyInfo.PropertyType.GetGenericArguments()[0];

                        var referencedTypeName = NormaliseName(referencedType.Name);
                        // skip non entity collections
                        if (!resourceTypes.ContainsKey(referencedTypeName))
                        {
                            continue;
                        }

                        // add reference set relationship
                        var referenceSetProperty = new ResourceProperty(
                            propertyInfo.Name,
                            ResourcePropertyKind.ResourceSetReference,
                            resourceTypes[NormaliseName(referencedType.Name)]);

                        resourceTypes[NormaliseName(exposedType.Name)].AddProperty(referenceSetProperty);

                        var inversePropertyInfo = FindInversePropertyFor(propertyInfo);
                        if (inversePropertyInfo == null)
                        {
                            var assocSet = new ResourceAssociationSet(propertyInfo.Name,
                                                                      new ResourceAssociationSetEnd(
                                                                          resourceSets[NormaliseName(exposedType.Name)],
                                                                          resourceTypes[NormaliseName(exposedType.Name)],
                                                                          referenceSetProperty),
                                                                      new ResourceAssociationSetEnd(
                                                                          resourceSets[NormaliseName(referencedType.Name)],
                                                                          resourceTypes[NormaliseName(referencedType.Name)],
                                                                          null));
                            referenceSetProperty.CustomState = assocSet;
                        }
                        else
                        {
                            // create the inverse resource property
                            ResourceProperty inverseReferenceProperty = null;
                            if (inversePropertyInfo.PropertyType.IsGenericType)
                            {
                                inverseReferenceProperty = new ResourceProperty(
                                    inversePropertyInfo.Name,
                                    ResourcePropertyKind.ResourceSetReference,
                                    resourceTypes[NormaliseName(inversePropertyInfo.PropertyType.GetGenericArguments()[0].Name)]);
                            }
                            else
                            {
                                inverseReferenceProperty = new ResourceProperty(
                                    inversePropertyInfo.Name,
                                    ResourcePropertyKind.ResourceReference,
                                    resourceTypes[NormaliseName(inversePropertyInfo.PropertyType.Name)]);
                            }

                            resourceTypes[NormaliseName(inversePropertyInfo.ReflectedType.Name)].AddProperty(inverseReferenceProperty);

                            // we need to create the other property as well as the association
                            var assocSet = new ResourceAssociationSet(referenceSetProperty.Name + "_" + inverseReferenceProperty.Name,
                                                                      new ResourceAssociationSetEnd(
                                                                          resourceSets[NormaliseName(exposedType.Name)],
                                                                          resourceTypes[NormaliseName(exposedType.Name)],
                                                                          referenceSetProperty),
                                                                      new ResourceAssociationSetEnd(
                                                                          resourceSets[NormaliseName(referencedType.Name)],
                                                                          resourceTypes[NormaliseName(referencedType.Name)],
                                                                          inverseReferenceProperty));
                            referenceSetProperty.CustomState     = assocSet;
                            inverseReferenceProperty.CustomState = assocSet;
                        }
                    }
                    else if (resourceTypes.Keys.Contains(NormaliseName(propertyInfo.PropertyType.Name)))
                    {
                        var referenceProperty = new ResourceProperty(
                            propertyInfo.Name,
                            ResourcePropertyKind.ResourceReference,
                            resourceTypes[NormaliseName(propertyInfo.PropertyType.Name)]);
                        resourceTypes[NormaliseName(exposedType.Name)].AddProperty(referenceProperty);
                        var inversePropertyInfo = FindInversePropertyFor(propertyInfo);
                        if (inversePropertyInfo == null)
                        {
                            var assocSet = new ResourceAssociationSet(referenceProperty.Name,
                                                                      new ResourceAssociationSetEnd(
                                                                          resourceSets[NormaliseName(exposedType.Name)],
                                                                          resourceTypes[NormaliseName(exposedType.Name)],
                                                                          referenceProperty),
                                                                      new ResourceAssociationSetEnd(
                                                                          resourceSets[NormaliseName(propertyInfo.PropertyType.Name)],
                                                                          resourceTypes[NormaliseName(propertyInfo.PropertyType.Name)],
                                                                          null));
                            referenceProperty.CustomState = assocSet;
                        }
                        else
                        {
                            // create the inverse resource property
                            ResourceProperty inverseReferenceProperty = null;

                            if (inversePropertyInfo.PropertyType.IsGenericType)
                            {
                                inverseReferenceProperty = new ResourceProperty(
                                    inversePropertyInfo.Name,
                                    ResourcePropertyKind.ResourceSetReference,
                                    resourceTypes[NormaliseName(inversePropertyInfo.PropertyType.GetGenericArguments()[0].Name)]);
                            }
                            else
                            {
                                inverseReferenceProperty = new ResourceProperty(
                                    inversePropertyInfo.Name,
                                    ResourcePropertyKind.ResourceReference,
                                    resourceTypes[NormaliseName(inversePropertyInfo.PropertyType.Name)]);
                            }

                            resourceTypes[NormaliseName(inversePropertyInfo.ReflectedType.Name)].AddProperty(inverseReferenceProperty);

                            // we need to create the other property as well as the association
                            var assocSet = new ResourceAssociationSet(referenceProperty.Name + "_" + inverseReferenceProperty.Name,
                                                                      new ResourceAssociationSetEnd(
                                                                          resourceSets[NormaliseName(exposedType.Name)],
                                                                          resourceTypes[NormaliseName(exposedType.Name)],
                                                                          referenceProperty),
                                                                      new ResourceAssociationSetEnd(
                                                                          resourceSets[NormaliseName(propertyInfo.PropertyType.Name)],
                                                                          resourceTypes[NormaliseName(propertyInfo.PropertyType.Name)],
                                                                          inverseReferenceProperty));
                            referenceProperty.CustomState        = assocSet;
                            inverseReferenceProperty.CustomState = assocSet;
                        }
                    }
                }
            }


            foreach (var resourceAssociationSet in associationSets.Values)
            {
                mdprovider.AddAssociationSet(resourceAssociationSet);
            }

            foreach (var resourceType in resourceTypes.Values)
            {
                mdprovider.AddResourceType(resourceType);
                mdprovider.AddResourceSet(resourceSets[resourceType.Name]);
            }

            _mdprovider = mdprovider;
            return(_mdprovider);
        }