private IEdmNavigationProperty AddDependentNavigation(EdmNavigationPropertyInfo edmDependentInfo, bool forceShadow)
        {
            IEdmNavigationProperty edmNavigationProperty = Microsoft.OData.Edm.EdmNavigationProperty.CreateNavigationProperty(DependentInfo.EdmType, edmDependentInfo);

            if (DependentNavigationProperty is OeShadowPropertyInfo || forceShadow)
            {
                if (DependentNavigationProperty == null)
                {
                    var shadowPropertyInfo = new OeShadowPropertyInfo(DependentInfo.ClrType, PrincipalInfo.ClrType, edmNavigationProperty.Name);
                    edmNavigationProperty = new OeEdmNavigationShadowProperty(edmNavigationProperty, shadowPropertyInfo);
                }
                else
                {
                    edmNavigationProperty = new OeEdmNavigationShadowProperty(edmNavigationProperty, DependentNavigationProperty);
                }
            }

            DependentInfo.EdmType.AddProperty(edmNavigationProperty);
            return(edmNavigationProperty);
        }
Exemple #2
0
        private IEdmNavigationProperty AddPrincipalNavigation(EdmNavigationPropertyInfo edmPrincipalInfo, bool forceShadow)
        {
            IEdmNavigationProperty edmNavigationProperty = Microsoft.OData.Edm.EdmNavigationProperty.CreateNavigationProperty(PrincipalInfo.EdmType, edmPrincipalInfo);

            if (PrincipalNavigationProperty is OeShadowPropertyInfo || forceShadow)
            {
                if (PrincipalNavigationProperty == null)
                {
                    Type propertyType       = edmNavigationProperty.Type.IsCollection() ? typeof(ICollection <>).MakeGenericType(DependentInfo.ClrType) : DependentInfo.ClrType;
                    var  shadowPropertyInfo = new OeShadowPropertyInfo(PrincipalInfo.ClrType, propertyType, edmNavigationProperty.Name);
                    edmNavigationProperty = new OeEdmNavigationShadowProperty(edmNavigationProperty, shadowPropertyInfo);
                }
                else
                {
                    edmNavigationProperty = new OeEdmNavigationShadowProperty(edmNavigationProperty, PrincipalNavigationProperty);
                }
            }

            PrincipalInfo.EdmType.AddProperty(edmNavigationProperty);
            return(edmNavigationProperty);
        }
Exemple #3
0
        public void Build(EntityTypeInfo typeInfo)
        {
            foreach ((PropertyInfo many, PropertyInfo join) in GetManyToManyInfo(_metadataProvider, typeInfo.ClrType))
            {
                if (many == null || many.DeclaringType != typeInfo.ClrType)
                {
                    continue;
                }

                IEdmNavigationProperty?joinNavigationProperty = GetJoinNavigationProperty(typeInfo, join.DeclaringType !);
                if (joinNavigationProperty == null)
                {
                    continue;
                }

                EntityTypeInfo principalInfo = _entityTypeInfos[join.PropertyType];
                EntityTypeInfo dependentInfo = _entityTypeInfos[many.DeclaringType];

                var edmDependentInfo = new EdmNavigationPropertyInfo()
                {
                    ContainsTarget      = true,
                    Name                = many.Name,
                    OnDelete            = EdmOnDeleteAction.None,
                    PrincipalProperties = principalInfo.EdmType.DeclaredKey,
                    Target              = principalInfo.EdmType,
                    TargetMultiplicity  = EdmMultiplicity.Many
                };
                IEdmNavigationProperty edmManyToManyProperty;
                if (typeInfo.ClrType.GetProperty(many.Name) == null)
                {
                    IEdmNavigationProperty edmNavigationProperty = EdmNavigationProperty.CreateNavigationProperty(dependentInfo.EdmType, edmDependentInfo);
                    edmManyToManyProperty = new OeEdmNavigationShadowProperty(edmNavigationProperty, many);
                    dependentInfo.EdmType.AddProperty(edmManyToManyProperty);
                }
                else
                {
                    edmManyToManyProperty = dependentInfo.EdmType.AddUnidirectionalNavigation(edmDependentInfo);
                }

                var targetNavigationProperty  = (IEdmNavigationProperty)_entityTypeInfos[join.DeclaringType !].EdmType.GetPropertyIgnoreCase(join.Name);