Beispiel #1
0
        private static PropertyInfo GetPrincipalNavigationProperty(OeEdmModelMetadataProvider metadataProvider,
                                                                   EntityTypeInfo principalInfo, EntityTypeInfo dependentInfo, PropertyInfo dependentNavigationProperty)
        {
            PropertyInfo inverseProperty = metadataProvider.GetInverseProperty(dependentNavigationProperty);

            if (inverseProperty != null)
            {
                return(inverseProperty);
            }

            foreach (PropertyInfo clrProperty in metadataProvider.GetProperties(principalInfo.ClrType))
            {
                if (clrProperty.PropertyType == dependentInfo.ClrType ||
                    Parsers.OeExpressionHelper.GetCollectionItemTypeOrNull(clrProperty.PropertyType) == dependentInfo.ClrType)
                {
                    inverseProperty = metadataProvider.GetInverseProperty(clrProperty);
                    if (inverseProperty == null || inverseProperty == dependentNavigationProperty)
                    {
                        return(clrProperty);
                    }
                }
            }

            return(null);
        }
        private static PropertyInfo GetPartnerProperty(OeEdmModelMetadataProvider metadataProvider, Type itemType, Type itemType2)
        {
            PropertyInfo partnerProperty   = null;
            PropertyInfo otherSideProperty = null;

            foreach (PropertyInfo propertyInfo in itemType2.GetProperties())
            {
                if (Parsers.OeExpressionHelper.IsPrimitiveType(propertyInfo.PropertyType))
                {
                    continue;
                }

                if (propertyInfo.PropertyType == itemType)
                {
                    if (partnerProperty == null)
                    {
                        partnerProperty = propertyInfo;
                    }
                    else
                    {
                        if (otherSideProperty != null)
                        {
                            return(null);
                        }

                        if (metadataProvider.GetInverseProperty(partnerProperty) == null)
                        {
                            otherSideProperty = propertyInfo;
                        }
                        else if (metadataProvider.GetInverseProperty(propertyInfo) == null)
                        {
                            otherSideProperty = partnerProperty;
                            partnerProperty   = propertyInfo;
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }
                else
                {
                    if (Parsers.OeExpressionHelper.GetCollectionItemType(propertyInfo.PropertyType) == null)
                    {
                        if (otherSideProperty != null)
                        {
                            return(null);
                        }

                        otherSideProperty = propertyInfo;
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            return(partnerProperty);
        }