Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public static FKeyInfo Create(OeEdmModelMetadataProvider metadataProvider,
                                      Dictionary <Type, EntityTypeInfo> entityTypes, EntityTypeInfo dependentInfo, PropertyInfo dependentNavigationProperty)
        {
            Type clrType = Parsers.OeExpressionHelper.GetCollectionItemTypeOrNull(dependentNavigationProperty.PropertyType) ?? dependentNavigationProperty.PropertyType;

            if (!entityTypes.TryGetValue(clrType, out EntityTypeInfo principalInfo))
            {
                return(null);
            }

            PropertyInfo[] dependentStructuralProperties = GetDependentStructuralProperties(metadataProvider, dependentInfo, dependentNavigationProperty);
            PropertyInfo   principalNavigationProperty   = GetPrincipalNavigationProperty(metadataProvider, principalInfo, dependentInfo, dependentNavigationProperty);

            if (dependentStructuralProperties.Length == 0)
            {
                if (principalNavigationProperty != null)
                {
                    return(null);
                }

                dependentStructuralProperties = metadataProvider.GetPrincipalToDependentWithoutDependent(dependentNavigationProperty);
                if (dependentStructuralProperties == null)
                {
                    throw new InvalidOperationException("not found dependent structural property " + dependentInfo.ClrType.Name + "Id for navigation property " + dependentNavigationProperty.Name);
                }

                return(new FKeyInfo(principalInfo, null, dependentStructuralProperties, dependentInfo, dependentNavigationProperty));
            }

            return(new FKeyInfo(dependentInfo, dependentNavigationProperty, dependentStructuralProperties, principalInfo, principalNavigationProperty));
        }
Exemplo n.º 3
0
        private static PropertyInfo[] GetDependentStructuralProperties(OeEdmModelMetadataProvider metadataProvider,
                                                                       EntityTypeInfo dependentInfo, PropertyInfo dependentProperty)
        {
            var dependentProperties = new List <PropertyInfo>();

            PropertyInfo[] fkey = metadataProvider.GetForeignKey(dependentProperty);
            if (fkey == null)
            {
                foreach (PropertyInfo propertyInfo in metadataProvider.GetProperties(dependentInfo.ClrType))
                {
                    fkey = metadataProvider.GetForeignKey(propertyInfo);
                    if (fkey != null && fkey.Length == 1 && fkey[0] == dependentProperty)
                    {
                        dependentProperties.Add(propertyInfo);
                    }
                }

                if (dependentProperties.Count == 0)
                {
                    PropertyInfo clrProperty = dependentInfo.ClrType.GetPropertyIgnoreCase(dependentProperty.Name + "id");
                    if (clrProperty != null)
                    {
                        dependentProperties.Add(clrProperty);
                    }
                }
            }
            else
            {
                dependentProperties.AddRange(fkey);
            }

            PropertyInfo[] dependentPropertyArray = dependentProperties.ToArray();
            metadataProvider.SortClrPropertyByOrder(dependentPropertyArray);
            return(dependentPropertyArray);
        }
Exemplo n.º 4
0
        public static FKeyInfo Create(OeEdmModelMetadataProvider metadataProvider,
                                      Dictionary <Type, EntityTypeInfo> entityTypes, EntityTypeInfo dependentInfo, PropertyInfo dependentNavigationProperty)
        {
            Type clrType = Parsers.OeExpressionHelper.GetCollectionItemType(dependentNavigationProperty.PropertyType);

            if (clrType == null)
            {
                clrType = dependentNavigationProperty.PropertyType;
            }

            if (!entityTypes.TryGetValue(clrType, out EntityTypeInfo principalInfo))
            {
                return(null);
            }

            PropertyInfo[] dependentStructuralProperties = GetDependentStructuralProperties(metadataProvider, dependentInfo, dependentNavigationProperty);
            PropertyInfo   principalNavigationProperty   = GetPrincipalNavigationProperty(metadataProvider, principalInfo, dependentInfo, dependentNavigationProperty);

            if (dependentStructuralProperties.Length == 0 && principalNavigationProperty != null)
            {
                return(null);
            }

            return(new FKeyInfo(dependentInfo, dependentNavigationProperty, dependentStructuralProperties, principalInfo, principalNavigationProperty));
        }
Exemplo n.º 5
0
        private static (PropertyInfo Many, PropertyInfo Join) GetManyToManyInfo(OeEdmModelMetadataProvider metadataProvider, Type entityType)
        {
            var collectionProperties = new List <PropertyInfo>();

            foreach (PropertyInfo propertyInfo in entityType.GetProperties())
            {
                if (!Parsers.OeExpressionHelper.IsPrimitiveType(propertyInfo.PropertyType) &&
                    Parsers.OeExpressionHelper.GetCollectionItemType(propertyInfo.PropertyType) != null)
                {
                    collectionProperties.Add(propertyInfo);
                }
            }

            foreach (PropertyInfo propertyInfo in collectionProperties)
            {
                if (metadataProvider.IsNotMapped(propertyInfo))
                {
                    Type itemType = Parsers.OeExpressionHelper.GetCollectionItemType(propertyInfo.PropertyType);
                    foreach (PropertyInfo propertyInfo2 in collectionProperties)
                    {
                        if (!metadataProvider.IsNotMapped(propertyInfo2))
                        {
                            Type         itemType2       = Parsers.OeExpressionHelper.GetCollectionItemType(propertyInfo2.PropertyType);
                            PropertyInfo partnerProperty = GetPartnerProperty(itemType, itemType2);
                            if (partnerProperty != null && itemType == partnerProperty.PropertyType)
                            {
                                return(propertyInfo, partnerProperty);
                            }
                        }
                    }
                }
            }

            return(default);
Exemplo n.º 6
0
        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);
        }
        public OeEdmModelBuilder(Db.OeDataAdapter dataAdapter, OeEdmModelMetadataProvider metadataProvider)
        {
            _dataAdapter      = dataAdapter;
            _metadataProvider = metadataProvider;

            _complexTypes            = new Dictionary <Type, EdmComplexType>();
            _enumTypes               = new Dictionary <Type, EdmEnumType>();
            _operationConfigurations = new List <OeOperationConfiguration>();
        }
Exemplo n.º 8
0
        public EntityTypeInfo(OeEdmModelMetadataProvider metadataProvider, Type clrType, EdmEntityType edmType)
        {
            _metadataProvider = metadataProvider;
            _clrType          = clrType;
            _edmType          = edmType;

            _keyProperties           = new List <KeyValuePair <PropertyInfo, EdmStructuralProperty> >(1);
            _navigationClrProperties = new List <FKeyInfo>();
        }
        public OeEdmModelBuilder(OeEdmModelMetadataProvider metadataProvider)
        {
            _metadataProvider = metadataProvider;

            _entitySets              = new Dictionary <String, Type>();
            _complexTypes            = new Dictionary <Type, EdmComplexType>();
            _enumTypes               = new Dictionary <Type, EdmEnumType>();
            _operationConfigurations = new List <OeOperationConfiguration>();
        }
Exemplo n.º 10
0
        public EntityTypeInfo(OeEdmModelMetadataProvider metadataProvider, Type clrType, String entitySetName)
        {
            _metadataProvider = metadataProvider;
            _clrType          = clrType;
            _entitySetName    = entitySetName;

            _edmType                 = new EdmEntityType(clrType.Namespace, clrType.Name);
            _keyProperties           = new List <KeyValuePair <PropertyDescriptor, EdmStructuralProperty> >(1);
            _navigationClrProperties = new List <FKeyInfo>(1);
        }
Exemplo n.º 11
0
        public EntityTypeInfo(OeEdmModelMetadataProvider metadataProvider, Type clrType, EdmEntityType edmType, bool isRefModel, bool isDbQuery)
        {
            _metadataProvider = metadataProvider;
            ClrType           = clrType;
            EdmType           = edmType;
            IsRefModel        = isRefModel;
            _isDbQuery        = isDbQuery;

            _keyProperties           = new List <KeyValuePair <PropertyInfo, EdmStructuralProperty> >(1);
            _navigationClrProperties = new List <FKeyInfo>();
        }
Exemplo n.º 12
0
        public OeEdmModelBuilder(OeEdmModelMetadataProvider metadataProvider, IDictionary <String, Type> entitySets)
        {
            _entityTypes = new Dictionary <Type, EntityTypeInfo>(entitySets.Count);
            foreach (KeyValuePair <String, Type> pair in entitySets)
            {
                _entityTypes.Add(pair.Value, new EntityTypeInfo(metadataProvider, pair.Value, pair.Key));
            }

            _complexTypes = new Dictionary <Type, EdmComplexType>();
            _enumTypes    = new Dictionary <Type, EdmEnumType>();
        }
Exemplo n.º 13
0
        private static IEnumerable <PropertyDescriptor> SortClrPropertyByOrder(OeEdmModelMetadataProvider metadataProvider, IEnumerable <PropertyDescriptor> clrProperties)
        {
            var propertyList = new List <Tuple <PropertyDescriptor, int> >(2);

            foreach (PropertyDescriptor clrProperty in clrProperties)
            {
                int order = metadataProvider.GetOrder(clrProperty);
                if (order == -1)
                {
                    return(clrProperties);
                }

                propertyList.Add(new Tuple <PropertyDescriptor, int>(clrProperty, order));
            }
            return(propertyList.OrderBy(t => t.Item2).Select(t => t.Item1));
        }
Exemplo n.º 14
0
        private static PropertyDescriptor[] GetDependentStructuralProperties(OeEdmModelMetadataProvider metadataProvider,
                                                                             EntityTypeInfo dependentInfo, PropertyDescriptor dependentProperty)
        {
            var dependentProperties = new List <PropertyDescriptor>(1);
            PropertyDescriptorCollection clrProperties = TypeDescriptor.GetProperties(dependentInfo.ClrType);

            PropertyDescriptor fkey = metadataProvider.GetForeignKey(dependentProperty);

            if (fkey == null)
            {
                foreach (PropertyDescriptor propertyDescriptor in clrProperties)
                {
                    fkey = metadataProvider.GetForeignKey(propertyDescriptor);
                    if (fkey == dependentProperty)
                    {
                        dependentProperties.Add(propertyDescriptor);
                    }
                }

                if (dependentProperties.Count == 0)
                {
                    PropertyDescriptor clrProperty = clrProperties.Find(dependentProperty.Name + "Id", true);
                    if (clrProperty != null)
                    {
                        dependentProperties.Add(clrProperty);
                    }
                }
            }
            else
            {
                dependentProperties.Add(fkey);
            }

            if (dependentProperties.Count == 1)
            {
                return(dependentProperties.ToArray());
            }
            else
            {
                return(SortClrPropertyByOrder(metadataProvider, dependentProperties).ToArray());
            }
        }
Exemplo n.º 15
0
 public ManyToManyBuilder(IEdmModel edmModel, OeEdmModelMetadataProvider metadataProvider, Dictionary <Type, EntityTypeInfo> entityTypeInfos)
 {
     _edmModel         = edmModel;
     _metadataProvider = metadataProvider;
     _entityTypeInfos  = entityTypeInfos;
 }
Exemplo n.º 16
0
        private static IEnumerable <(PropertyInfo Many, PropertyInfo Join)> GetManyToManyInfo(OeEdmModelMetadataProvider metadataProvider, Type entityType)
        {
            IReadOnlyList <PropertyInfo> properties = metadataProvider.GetManyToManyProperties(entityType);

            for (int i = 0; i < properties.Count; i++)
            {
                Type itemType = Parsers.OeExpressionHelper.GetCollectionItemType(properties[i].PropertyType);
                foreach (PropertyInfo property2 in metadataProvider.GetProperties(entityType))
                {
                    Type itemType2 = Parsers.OeExpressionHelper.GetCollectionItemTypeOrNull(property2.PropertyType);
                    if (itemType2 != null)
                    {
                        PropertyInfo partnerProperty = GetPartnerProperty(metadataProvider, itemType, itemType2);
                        if (partnerProperty != null && itemType == partnerProperty.PropertyType)
                        {
                            yield return(properties[i], partnerProperty);

                            break;
                        }
                    }
                }
            }
        }