Exemple #1
0
        protected override Object CreateEntity(ODataResourceBase resource, IReadOnlyList <NavigationInfo> navigationProperties)
        {
            Db.OeEntitySetAdapter entitySetAdapter = TestHelper.FindEntitySetAdapterByTypeName(EntitySetAdapters, resource.TypeName);
            Type entityType = entitySetAdapter.EntityType;
            var  openType   = (SortedDictionary <String, Object>)CreateEntity(entityType, resource);

            Dictionary <PropertyInfo, NavigationInfo> propertyInfos = null;

            foreach (NavigationInfo navigationInfo in navigationProperties)
            {
                Object value = navigationInfo.Value;

                if (navigationInfo.Count != null || navigationInfo.NextPageLink != null)
                {
                    PropertyInfo clrProperty = entityType.GetProperty(navigationInfo.Name);
                    if (value == null && navigationInfo.NextPageLink != null)
                    {
                        if (navigationInfo.IsCollection)
                        {
                            value = new List <SortedDictionary <String, Object> >();
                        }
                        else
                        {
                            value = new SortedDictionary <String, Object>();
                        }
                    }
                    base.NavigationProperties.Add(value, navigationInfo);

                    if (propertyInfos == null)
                    {
                        propertyInfos = new Dictionary <PropertyInfo, NavigationInfo>(navigationProperties.Count);
                        base.NavigationInfoEntities.Add(openType, propertyInfos);
                    }
                    propertyInfos.Add(clrProperty, navigationInfo);
                }

                if (value == null)
                {
                    PropertyInfo clrProprety = entityType.GetProperty(navigationInfo.Name);
                    Type         type        = OeExpressionHelper.GetCollectionItemTypeOrNull(clrProprety.PropertyType);
                    if (type == null)
                    {
                        type = clrProprety.PropertyType;
                    }

                    if (OeExpressionHelper.IsEntityType(type))
                    {
                        value = DBNull.Value;
                    }
                }

                openType.Add(navigationInfo.Name, value);
            }

            return(openType);
        }
        protected virtual Object CreateEntity(ODataResourceBase resource, IReadOnlyList <NavigationInfo> navigationProperties)
        {
            Db.OeEntitySetAdapter entitySetAdapter = TestHelper.FindEntitySetAdapterByTypeName(EntitySetAdapters, resource.TypeName);
            Object entity = CreateEntity(entitySetAdapter.EntityType, resource);
            Dictionary <PropertyInfo, NavigationInfo> propertyInfos = null;

            foreach (NavigationInfo navigationInfo in navigationProperties)
            {
                PropertyInfo clrProperty = entitySetAdapter.EntityType.GetProperty(navigationInfo.Name);
                Object       value       = navigationInfo.Value;

                if ((navigationInfo.Count == null && navigationInfo.NextPageLink == null))
                {
                    if (clrProperty.GetSetMethod() != null)
                    {
                        clrProperty.SetValue(entity, value);
                    }
                }
                else
                {
                    if (value == null && navigationInfo.NextPageLink != null)
                    {
                        if (navigationInfo.IsCollection)
                        {
                            value = CreateCollection(clrProperty.PropertyType);
                        }
                        else
                        {
                            value = Activator.CreateInstance(clrProperty.PropertyType);
                        }
                    }

                    clrProperty.SetValue(entity, value);
                    if (value != null)
                    {
                        NavigationProperties.Add(value, navigationInfo);
                    }

                    if (propertyInfos == null)
                    {
                        propertyInfos = new Dictionary <PropertyInfo, NavigationInfo>(navigationProperties.Count);
                        NavigationInfoEntities.Add(entity, propertyInfos);
                    }
                    propertyInfos.Add(clrProperty, navigationInfo);
                }
            }

            return(entity);
        }
Exemple #3
0
        protected Object CreateEntity(ODataResource resource, IReadOnlyList <NavigationProperty> navigationProperties)
        {
            Db.OeEntitySetAdapter entitySetAdapter = TestHelper.FindEntitySetAdapterByTypeName(EntitySetAdapters, resource.TypeName);
            Object entity = OeEdmClrHelper.CreateEntity(entitySetAdapter.EntityType, resource);
            Dictionary <PropertyInfo, ODataResourceSetBase> propertyInfos = null;

            foreach (NavigationProperty navigationProperty in navigationProperties)
            {
                PropertyInfo clrProperty = entitySetAdapter.EntityType.GetProperty(navigationProperty.Name);
                Object       value       = navigationProperty.Value;

                if (navigationProperty.ResourceSet == null || (navigationProperty.ResourceSet.Count == null && navigationProperty.ResourceSet.NextPageLink == null))
                {
                    if (clrProperty.GetSetMethod() != null)
                    {
                        clrProperty.SetValue(entity, value);
                    }
                    continue;
                }

                if (value == null && navigationProperty.ResourceSet.NextPageLink != null)
                {
                    value = CreateCollection(clrProperty.PropertyType);
                }

                clrProperty.SetValue(entity, value);
                if (value is IEnumerable collection)
                {
                    NavigationProperties.Add(collection, navigationProperty.ResourceSet);

                    if (propertyInfos == null)
                    {
                        propertyInfos = new Dictionary <PropertyInfo, ODataResourceSetBase>(navigationProperties.Count);
                        NavigationPropertyEntities.Add(entity, propertyInfos);
                    }
                    propertyInfos.Add(clrProperty, navigationProperty.ResourceSet);
                }
            }

            return(entity);
        }