Exemplo n.º 1
0
        public IHttpActionResult GetName(int key)
        {
            EdmEntityObjectCollection customers = GetCustomers();
            EdmEntityObject           customer  = customers.FirstOrDefault(e =>
            {
                object customerId;
                if (e.TryGetPropertyValue("CustomerId", out customerId))
                {
                    return((int)customerId == key);
                }

                return(false);
            }) as EdmEntityObject;

            if (customer == null)
            {
                return(NotFound());
            }

            object name;

            customer.TryGetPropertyValue("Name", out name);
            if (name == null)
            {
                return(NotFound());
            }

            return(Ok(name, name.GetType()));
        }
Exemplo n.º 2
0
        protected IEnumerable <IEdmEntityObject> GetFilteredResult(IEnumerable <Dictionary <string, object> > group, string query, ParseContext parseContext)
        {
            // Create collection from group
            var collectionEntityTypeKey = parseContext.LatestStateDictionary
                                          .Keys.FirstOrDefault(p => p.Contains("collectionentitytype"));
            var entityRef     = (EdmEntityTypeReference)parseContext.LatestStateDictionary[collectionEntityTypeKey];
            var collectionRef = new EdmCollectionTypeReference(new EdmCollectionType(entityRef));
            var collection    = new EdmEntityObjectCollection(collectionRef);

            foreach (var entity in group)
            {
                var obj = new EdmEntityObject(entityRef);
                foreach (var kvp in entity)
                {
                    obj.TrySetPropertyValue(kvp.Key, kvp.Value);
                }
                collection.Add(obj);
            }
            // Create filter query using the entity supplied in the lateststatedictionary
            var serviceRoot    = new Uri(RequestFilterConstants.ODataServiceRoot);
            var resource       = entityRef.Definition.FullTypeName().Split(".").Last();
            var filterQuery    = "/" + resource + "?$filter=" + Uri.EscapeDataString(query.Substring(1, query.Length - 2).Replace("''", "'"));
            var oDataUriParser = new ODataUriParser(parseContext.Model, new Uri(filterQuery, UriKind.Relative));

            // Parse filterquery
            var filter         = oDataUriParser.ParseFilter();
            var odataFilter    = new ODataFilterPredicateParser();
            var filteredResult = odataFilter.ApplyFilter(parseContext.EdmEntityTypeSettings.FirstOrDefault(), collection, filter.Expression);

            return(filteredResult);
        }
Exemplo n.º 3
0
 public static void Get(
     string dataSourceName,
     IEdmEntityTypeReference entityType,
     EdmEntityObjectCollection collection)
 {
     GetDataSource(dataSourceName).Get(entityType, collection);
 }
Exemplo n.º 4
0
        private static void BuildCustomers(IEdmModel model)
        {
            IEdmEntityType customerType = model.SchemaElements.OfType <IEdmEntityType>().First(e => e.Name == "Customer");

            IEdmEntityObject[] untypedCustomers = new IEdmEntityObject[6];
            for (int i = 1; i <= 5; i++)
            {
                dynamic untypedCustomer = new EdmEntityObject(customerType);
                untypedCustomer.ID      = i;
                untypedCustomer.Name    = string.Format("Name {0}", i);
                untypedCustomer.SSN     = "SSN-" + i + "-" + (100 + i);
                untypedCustomers[i - 1] = untypedCustomer;
            }

            // create a special customer for "PATCH"
            dynamic customer = new EdmEntityObject(customerType);

            customer.ID         = 6;
            customer.Name       = "Name 6";
            customer.SSN        = "SSN-6-T-006";
            untypedCustomers[5] = customer;

            IEdmCollectionTypeReference entityCollectionType =
                new EdmCollectionTypeReference(
                    new EdmCollectionType(
                        new EdmEntityTypeReference(customerType, isNullable: false)));

            Customers = new EdmEntityObjectCollection(entityCollectionType, untypedCustomers.ToList());
        }
 public static void Get(
     string dataSourceName,
     IEdmEntityTypeReference entityType,
     EdmEntityObjectCollection collection)
 {
     GetDataSource(dataSourceName).Get(entityType, collection);
 }
Exemplo n.º 6
0
        private static EdmEntityObjectCollection GetCustomers()
        {
            if (_untypedSimpleOpenCustormers != null)
            {
                return(_untypedSimpleOpenCustormers);
            }

            IEdmModel       edmModel     = OpenEntityTypeTests.GetUntypedEdmModel();
            IEdmEntityType  customerType = edmModel.SchemaElements.OfType <IEdmEntityType>().First(c => c.Name == "UntypedSimpleOpenCustomer");
            EdmEntityObject customer     = new EdmEntityObject(customerType);

            customer.TrySetPropertyValue("CustomerId", 1);

            //Add Numbers primitive collection property
            customer.TrySetPropertyValue("DeclaredNumbers", new[] { 1, 2 });

            //Add Color, Colors enum(collection) property
            IEdmEnumType  colorType = edmModel.SchemaElements.OfType <IEdmEnumType>().First(c => c.Name == "Color");
            EdmEnumObject color     = new EdmEnumObject(colorType, "Red");
            EdmEnumObject color2    = new EdmEnumObject(colorType, "0");
            EdmEnumObject color3    = new EdmEnumObject(colorType, "Red");

            customer.TrySetPropertyValue("Color", color);

            List <IEdmEnumObject> colorList = new List <IEdmEnumObject>();

            colorList.Add(color);
            colorList.Add(color2);
            colorList.Add(color3);
            IEdmCollectionTypeReference enumCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(colorType.ToEdmTypeReference(false)));
            EdmEnumObjectCollection     colors             = new EdmEnumObjectCollection(enumCollectionType, colorList);

            customer.TrySetPropertyValue("Colors", colors);
            customer.TrySetPropertyValue("DeclaredColors", colors);

            //Add Addresses complex(collection) property
            EdmComplexType addressType =
                edmModel.SchemaElements.OfType <IEdmComplexType>().First(c => c.Name == "Address") as EdmComplexType;
            EdmComplexObject address = new EdmComplexObject(addressType);

            address.TrySetPropertyValue("Street", "No1");
            EdmComplexObject address2 = new EdmComplexObject(addressType);

            address2.TrySetPropertyValue("Street", "No2");

            List <IEdmComplexObject> addressList = new List <IEdmComplexObject>();

            addressList.Add(address);
            addressList.Add(address2);
            IEdmCollectionTypeReference complexCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(addressType.ToEdmTypeReference(false)));
            EdmComplexObjectCollection  addresses             = new EdmComplexObjectCollection(complexCollectionType, addressList);

            customer.TrySetPropertyValue("DeclaredAddresses", addresses);

            EdmEntityObjectCollection customers = new EdmEntityObjectCollection(new EdmCollectionTypeReference(new EdmCollectionType(customerType.ToEdmTypeReference(false))));

            customers.Add(customer);
            _untypedSimpleOpenCustormers = customers;
            return(_untypedSimpleOpenCustormers);
        }
Exemplo n.º 7
0
        private static void BuildOrderss(IEdmModel model)
        {
            IEdmEntityType orderType = model.SchemaElements.OfType <IEdmEntityType>().First(e => e.Name == "Order");

            Guid[] guids =
            {
                new Guid("196B3584-EF3D-41FD-90B4-76D59F9B929C"),
                new Guid("6CED5600-28BA-40EE-A2DF-E80AFADBE6C7"),
                new Guid("75036B94-C836-4946-8CC8-054CF54060EC"),
                new Guid("B3FF5460-6E77-4678-B959-DCC1C4937FA7"),
                new Guid("ED773C85-4E3C-4FC4-A3E9-9F1DA0A626DA")
            };

            IEdmEntityObject[] untypedOrders = new IEdmEntityObject[5];
            for (int i = 0; i < 5; i++)
            {
                dynamic untypedOrder = new EdmEntityObject(orderType);
                untypedOrder.OrderId = i;
                untypedOrder.Name    = string.Format("Order-{0}", i);
                untypedOrder.Token   = guids[i];
                untypedOrder.Amount  = 10 + i;
                untypedOrders[i]     = untypedOrder;
            }

            IEdmCollectionTypeReference entityCollectionType =
                new EdmCollectionTypeReference(
                    new EdmCollectionType(
                        new EdmEntityTypeReference(orderType, isNullable: false)));

            Orders = new EdmEntityObjectCollection(entityCollectionType, untypedOrders.ToList());
        }
        private static void BuildCustomers(IEdmModel model)
        {
            IEdmEntityType customerType = model.SchemaElements.OfType<IEdmEntityType>().First(e => e.Name == "Customer");

            IEdmEntityObject[] untypedCustomers = new IEdmEntityObject[6];
            for (int i = 1; i <= 5; i++)
            {
                dynamic untypedCustomer = new EdmEntityObject(customerType);
                untypedCustomer.ID = i;
                untypedCustomer.Name = string.Format("Name {0}", i);
                untypedCustomer.SSN = "SSN-" + i + "-" + (100 + i);
                untypedCustomers[i-1] = untypedCustomer;
            }

            // create a special customer for "PATCH"
            dynamic customer = new EdmEntityObject(customerType);
            customer.ID = 6;
            customer.Name = "Name 6";
            customer.SSN = "SSN-6-T-006";
            untypedCustomers[5] = customer;

            IEdmCollectionTypeReference entityCollectionType =
                new EdmCollectionTypeReference(
                    new EdmCollectionType(
                        new EdmEntityTypeReference(customerType, isNullable: false)));

            Customers = new EdmEntityObjectCollection(entityCollectionType, untypedCustomers.ToList());
        }
Exemplo n.º 9
0
        public EdmEntityObjectCollection Get(IEdmCollectionType collectionType, ODataQueryOptions queryOptions)
        {
            var entityType = collectionType.ElementType.Definition as EdmEntityType;
            var collection = new EdmEntityObjectCollection(new EdmCollectionTypeReference(collectionType, true));

            if (entityType != null)
            {
                using (var connection = new SqlConnection(_connectionString))
                {
                    var sqlBuilder = new SqlQueryBuilder(queryOptions);
                    var sql        = sqlBuilder.ToSql();

                    Console.WriteLine(sql);

                    IEnumerable <dynamic> rows = connection.Query <dynamic>(sql);

                    foreach (dynamic row in rows)
                    {
                        var entity = CreateEdmEntity(entityType, row);
                        collection.Add(entity);
                    }
                }
            }

            return(collection);
        }
 public void Get(
     ODataQueryOptions queryOptions,
     IEdmEntityTypeReference entityType,
     EdmEntityObjectCollection collection)
 {
     _dataSource.Get(queryOptions, entityType, collection);
 }
Exemplo n.º 11
0
        public static EdmEntityObjectCollection ToCollection(this IEnumerable <IODataEntityObject> oDataEntities, IEdmCollectionType collectionType)
        {
            var collection = new EdmEntityObjectCollection(new EdmCollectionTypeReference(collectionType));

            collection.AddRange(oDataEntities.Cast <ServiceApiEdmEntityObject>().ToArray());

            return(collection);
        }
        public void GetEdmType_Returns_EdmTypeInitializedByCtor()
        {
            IEdmTypeReference elementType = new EdmEntityTypeReference(new EdmEntityType("NS", "Entity"), isNullable: false);
            IEdmCollectionTypeReference collectionType = new EdmCollectionTypeReference(new EdmCollectionType(elementType), isNullable: false);

            var edmObject = new EdmEntityObjectCollection(collectionType);
            Assert.Same(collectionType, edmObject.GetEdmType());
        }
        public void GetEdmType_Returns_EdmTypeInitializedByCtor()
        {
            IEdmTypeReference           elementType    = new EdmEntityTypeReference(new EdmEntityType("NS", "Entity"), isNullable: false);
            IEdmCollectionTypeReference collectionType = new EdmCollectionTypeReference(new EdmCollectionType(elementType));

            var edmObject = new EdmEntityObjectCollection(collectionType);

            Assert.Same(collectionType, edmObject.GetEdmType());
        }
Exemplo n.º 14
0
        /// <summary>
        /// Writes the given object specified by the parameter graph as a whole using the given messageWriter and writeContext.
        /// </summary>
        /// <param name="graph">The object to be written</param>
        /// <param name="type">The type of the object to be written.</param>
        /// <param name="messageWriter">The <see cref="ODataMessageWriter"/> to be used for writing.</param>
        /// <param name="writeContext">The <see cref="ODataSerializerContext"/>.</param>
        public override void WriteObject(object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)
        {
            if (graph is EnumerableQuery <IEdmEntityObject> )
            {
                var list = ((EnumerableQuery <IEdmEntityObject>)graph).AsIList();
                var entityCollectionType = new EdmCollectionTypeReference((EdmCollectionType)((EdmEntitySet)writeContext.NavigationSource).Type);
                graph = new EdmEntityObjectCollection(entityCollectionType, list);
            }

            base.WriteObject(graph, type, messageWriter, writeContext);
        }
Exemplo n.º 15
0
 public void Get(IEdmEntityTypeReference entityType, EdmEntityObjectCollection collection)
 {
     EdmEntityObject entity = new EdmEntityObject(entityType);
     entity.TrySetPropertyValue("Name", "Foo");
     entity.TrySetPropertyValue("ID", 100);
     collection.Add(entity);
     entity = new EdmEntityObject(entityType);
     entity.TrySetPropertyValue("Name", "Bar");
     entity.TrySetPropertyValue("ID", 101);
     collection.Add(entity);
 }
Exemplo n.º 16
0
        public void Get(IEdmEntityTypeReference entityType, EdmEntityObjectCollection collection)
        {
            EdmEntityObject entity = new EdmEntityObject(entityType);

            entity.TrySetPropertyValue("Name", "Foo");
            entity.TrySetPropertyValue("ID", 100);
            collection.Add(entity);
            entity = new EdmEntityObject(entityType);
            entity.TrySetPropertyValue("Name", "Bar");
            entity.TrySetPropertyValue("ID", 101);
            collection.Add(entity);
        }
        public static void PrepareHttpResponseMessage(ref HttpResponseMessage msg, string mediaType, DataObjectEdmModel model, byte[] buffer)
        {
            List <IEdmEntityObject> edmObjList = new List <IEdmEntityObject>();
            var edmObj = new EdmEntityObject(model.GetEdmEntityType(typeof(DataObject)));

            edmObj.TrySetPropertyValue("__PrimaryKey", buffer);
            edmObjList.Add(edmObj);
            IEdmCollectionTypeReference entityCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(edmObj.GetEdmType()));
            EdmEntityObjectCollection   collection           = new EdmEntityObjectCollection(entityCollectionType, edmObjList);

            msg.Content = new ObjectContent(typeof(EdmEntityObjectCollection), collection, new RawOutputFormatter(), mediaType);
        }
 private dynamic CreateOrders(int i)
 {
     EdmEntityObject[] orders = new EdmEntityObject[i];
     for (int j = 0; j < i; j++)
     {
         dynamic order = new EdmEntityObject(OrderType);
         order.Id = j;
         order.ShippingAddress = CreateAddress(j);
         orders[j] = order;
     }
     var collection = new EdmEntityObjectCollection(new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(OrderType, false))), orders);
     return collection;
 }
Exemplo n.º 19
0
        // wget -UseBasicParsing 'http://localhost:44377/OData/Persons'
        public IHttpActionResult Get()
        {
            var path = this.Request.ODataProperties().Path;
            var edmCollectionType = (IEdmCollectionType)path.EdmType;
            var edmEntityType     = (IEdmEntityType)edmCollectionType.ElementType.Definition;

            var result = new EdmEntityObjectCollection(
                new EdmCollectionTypeReference(edmCollectionType),
                new List <IEdmEntityObject> {
                CreatePerson(edmEntityType, 1), CreatePerson(edmEntityType, 2)
            }
                );

            return(this.Ok(result));
        }
        public void Get(IEdmEntityTypeReference entityType, EdmEntityObjectCollection collection)
        {
            EdmEntityObject entity = new EdmEntityObject(entityType);
            entity.TrySetPropertyValue("Name", "Foo");
            entity.TrySetPropertyValue("ID", 100);
            entity.TrySetPropertyValue("School", Createchool(99, new DateTimeOffset(2016, 1, 19, 1, 2, 3, TimeSpan.Zero), entity.ActualEdmType));
            collection.Add(entity);

            entity = new EdmEntityObject(entityType);
            entity.TrySetPropertyValue("Name", "Bar");
            entity.TrySetPropertyValue("ID", 101);
            entity.TrySetPropertyValue("School", Createchool(99, new DateTimeOffset(1978, 11, 15, 1, 2, 3, TimeSpan.Zero), entity.ActualEdmType));

            collection.Add(entity);
        }
Exemplo n.º 21
0
        public void Get(IEdmEntityTypeReference entityType, EdmEntityObjectCollection collection)
        {
            EdmEntityObject entity = new EdmEntityObject(entityType);
            entity.TrySetPropertyValue("Name", "abc");
            entity.TrySetPropertyValue("ID", 1);
            entity.TrySetPropertyValue("DetailInfo", CreateDetailInfo(88, "abc_detailinfo", entity.ActualEdmType));

            collection.Add(entity);
            entity = new EdmEntityObject(entityType);
            entity.TrySetPropertyValue("Name", "def");
            entity.TrySetPropertyValue("ID", 2);
            entity.TrySetPropertyValue("DetailInfo", CreateDetailInfo(99, "def_detailinfo", entity.ActualEdmType));

            collection.Add(entity);
        }
Exemplo n.º 22
0
        public void Get(IEdmEntityTypeReference entityType, EdmEntityObjectCollection collection)
        {
            EdmEntityObject entity = new EdmEntityObject(entityType);

            entity.TrySetPropertyValue("Name", "abc");
            entity.TrySetPropertyValue("ID", 1);
            entity.TrySetPropertyValue("DetailInfo", CreateDetailInfo(88, "abc_detailinfo", entity.ActualEdmType));

            collection.Add(entity);
            entity = new EdmEntityObject(entityType);
            entity.TrySetPropertyValue("Name", "def");
            entity.TrySetPropertyValue("ID", 2);
            entity.TrySetPropertyValue("DetailInfo", CreateDetailInfo(99, "def_detailinfo", entity.ActualEdmType));

            collection.Add(entity);
        }
Exemplo n.º 23
0
        // Get entityset
        public EdmEntityObjectCollection Get()
        {
            // Get entity set's EDM type: A collection type.
            ODataPath               path           = Request.ODataProperties().Path;
            IEdmCollectionType      collectionType = (IEdmCollectionType)path.EdmType;
            IEdmEntityTypeReference entityType     = collectionType.ElementType.AsEntity();

            // Create an untyped collection with the EDM collection type.
            EdmEntityObjectCollection collection =
                new EdmEntityObjectCollection(new EdmCollectionTypeReference(collectionType));

            // Add untyped objects to collection.
            DataSourceProvider.Get((string)Request.Properties[Constants.ODataDataSource], entityType, collection);

            return(collection);
        }
        // Get entityset
        public EdmEntityObjectCollection Get()
        {
            // Get entity set's EDM type: A collection type.
            ODataPath path = Request.ODataProperties().Path;
            IEdmCollectionType collectionType = (IEdmCollectionType)path.EdmType;
            IEdmEntityTypeReference entityType = collectionType.ElementType.AsEntity();

            // Create an untyped collection with the EDM collection type.
            EdmEntityObjectCollection collection =
                new EdmEntityObjectCollection(new EdmCollectionTypeReference(collectionType));

            // Add untyped objects to collection.
            DataSourceProvider.Get((string)Request.Properties[Constants.ODataDataSource], entityType, collection);

            return collection;
        }
Exemplo n.º 25
0
        public void Get(IEdmEntityTypeReference entityType, EdmEntityObjectCollection collection)
        {
            EdmEntityObject entity = new EdmEntityObject(entityType);

            entity.TrySetPropertyValue("Name", "Foo");
            entity.TrySetPropertyValue("ID", 100);
            entity.TrySetPropertyValue("School", Createchool(99, new DateTimeOffset(2016, 1, 19, 1, 2, 3, TimeSpan.Zero), entity.ActualEdmType));
            collection.Add(entity);

            entity = new EdmEntityObject(entityType);
            entity.TrySetPropertyValue("Name", "Bar");
            entity.TrySetPropertyValue("ID", 101);
            entity.TrySetPropertyValue("School", Createchool(99, new DateTimeOffset(1978, 11, 15, 1, 2, 3, TimeSpan.Zero), entity.ActualEdmType));

            collection.Add(entity);
        }
        public static bool TryCreateInstance(Type collectionType, IEdmCollectionTypeReference edmCollectionType, Type elementType, out IEnumerable instance)
        {
            Contract.Assert(collectionType != null);

            if (collectionType == typeof(EdmComplexObjectCollection))
            {
                instance = new EdmComplexObjectCollection(edmCollectionType);
                return(true);
            }
            else if (collectionType == typeof(EdmEntityObjectCollection))
            {
                instance = new EdmEntityObjectCollection(edmCollectionType);
                return(true);
            }
            else if (collectionType == typeof(EdmEnumObjectCollection))
            {
                instance = new EdmEnumObjectCollection(edmCollectionType);
                return(true);
            }
            else if (TypeHelper.IsGenericType(collectionType))
            {
                Type genericDefinition = collectionType.GetGenericTypeDefinition();
                if (genericDefinition == typeof(IEnumerable <>) ||
                    genericDefinition == typeof(ICollection <>) ||
                    genericDefinition == typeof(IList <>))
                {
                    instance = Activator.CreateInstance(typeof(List <>).MakeGenericType(elementType)) as IEnumerable;
                    return(true);
                }
            }

            if (collectionType.IsArray)
            {
                // We dont know the size of the collection in advance. So, create a list and later call ToArray.
                instance = Activator.CreateInstance(typeof(List <>).MakeGenericType(elementType)) as IEnumerable;
                return(true);
            }

            if (collectionType.GetConstructor(Type.EmptyTypes) != null && !collectionType.IsAbstract)
            {
                instance = Activator.CreateInstance(collectionType) as IEnumerable;
                return(true);
            }

            instance = null;
            return(false);
        }
Exemplo n.º 27
0
            internal static object ConvertFeed(ODataMessageReader oDataMessageReader, IEdmTypeReference edmTypeReference, ODataDeserializerContext readContext)
            {
                IEdmCollectionTypeReference collectionType = edmTypeReference.AsCollection();

                EdmEntitySet tempEntitySet = new EdmEntitySet(readContext.Model.EntityContainer, "temp",
                                                              collectionType.ElementType().AsEntity().EntityDefinition());

                ODataReader odataReader = oDataMessageReader.CreateODataFeedReader(tempEntitySet,
                                                                                   collectionType.ElementType().AsEntity().EntityDefinition());
                ODataFeedWithEntries feed =
                    ODataEntityDeserializer.ReadEntryOrFeed(odataReader) as ODataFeedWithEntries;

                ODataFeedDeserializer feedDeserializer =
                    (ODataFeedDeserializer)DeserializerProvider.GetEdmTypeDeserializer(collectionType);

                object      result     = feedDeserializer.ReadInline(feed, collectionType, readContext);
                IEnumerable enumerable = result as IEnumerable;

                if (enumerable != null)
                {
                    IEnumerable newEnumerable = CovertFeedIds(enumerable, feed, collectionType, readContext);
                    if (readContext.IsUntyped)
                    {
                        EdmEntityObjectCollection entityCollection =
                            new EdmEntityObjectCollection(collectionType);
                        foreach (EdmEntityObject entity in newEnumerable)
                        {
                            entityCollection.Add(entity);
                        }

                        return(entityCollection);
                    }
                    else
                    {
                        IEdmTypeReference elementTypeReference = collectionType.ElementType();

                        Type elementClrType = EdmLibHelpers.GetClrType(elementTypeReference,
                                                                       readContext.Model);
                        IEnumerable castedResult =
                            CastMethodInfo.MakeGenericMethod(elementClrType)
                            .Invoke(null, new object[] { newEnumerable }) as IEnumerable;
                        return(castedResult);
                    }
                }

                return(null);
            }
Exemplo n.º 28
0
        public static IEdmObject ConvertToEdmObject(this IEnumerable enumerable, IEdmCollectionTypeReference collectionType)
        {
            Contract.Assert(enumerable != null);
            Contract.Assert(collectionType != null);

            IEdmTypeReference elementType = collectionType.ElementType();

            if (elementType.IsEntity())
            {
                EdmEntityObjectCollection entityCollection =
                    new EdmEntityObjectCollection(collectionType);

                foreach (EdmEntityObject entityObject in enumerable)
                {
                    entityCollection.Add(entityObject);
                }

                return(entityCollection);
            }
            else if (elementType.IsComplex())
            {
                EdmComplexObjectCollection complexCollection =
                    new EdmComplexObjectCollection(collectionType);

                foreach (EdmComplexObject complexObject in enumerable)
                {
                    complexCollection.Add(complexObject);
                }

                return(complexCollection);
            }
            else if (elementType.IsEnum())
            {
                EdmEnumObjectCollection enumCollection =
                    new EdmEnumObjectCollection(collectionType);

                foreach (EdmEnumObject enumObject in enumerable)
                {
                    enumCollection.Add(enumObject);
                }

                return(enumCollection);
            }

            return(null);
        }
Exemplo n.º 29
0
        public IHttpActionResult Get()
        {
            IEdmModel      model        = Request.GetModel();
            IEdmEntityType customerType = model.SchemaElements.OfType <IEdmEntityType>().First(e => e.Name == "Customer");

            EdmEntityObject customer = new EdmEntityObject(customerType);

            customer.TrySetPropertyValue("Id", 1);
            customer.TrySetPropertyValue("Tony", 1);

            EdmEntityObjectCollection customers =
                new EdmEntityObjectCollection(
                    new EdmCollectionTypeReference(new EdmCollectionType(customerType.ToEdmTypeReference(false))));

            customers.Add(customer);
            return(Ok(customers));
        }
Exemplo n.º 30
0
        // Get entityset
        // odata/{datasource}/{entityset}
        public EdmEntityObjectCollection Get(string datasource)
        {
            // Get entity set's EDM type: A collection type.
            ODataPath               path           = Request.ODataFeature().Path;
            IEdmCollectionType      collectionType = (IEdmCollectionType)path.Last().EdmType;
            IEdmEntityTypeReference entityType     = collectionType.ElementType.AsEntity();

            // Create an untyped collection with the EDM collection type.
            EdmEntityObjectCollection collection =
                new EdmEntityObjectCollection(new EdmCollectionTypeReference(collectionType));

            // Add untyped objects to collection.
            IDataSource ds = _provider.DataSources[datasource];

            ds.Get(entityType, collection);

            return(collection);
        }
Exemplo n.º 31
0
        // Get entityset
        public IActionResult Get()
        {
            // Get entity set's EDM type: A collection type.
            ODataPath               path           = Request.ODataFeature().Path;
            IEdmCollectionType      collectionType = (IEdmCollectionType)path.EdmType;
            IEdmEntityTypeReference entityType     = collectionType.ElementType.AsEntity();

            // Create an untyped collection with the EDM collection type.
            EdmEntityObjectCollection collection =
                new EdmEntityObjectCollection(new EdmCollectionTypeReference(collectionType));

            string sourceString = Request.GetDataSource();

            // Add untyped objects to collection.
            DataSourceProvider.Get(sourceString, entityType, collection);

            return(collection);
        }
Exemplo n.º 32
0
        private EdmEntityObjectCollection GetCustomers()
        {
            IEdmModel edmModel = Request.ODataProperties().Model;

            IEdmEntityType  customerType = edmModel.SchemaElements.OfType <IEdmEntityType>().Single(e => e.Name == "Customer");
            IEdmEnumType    colorType    = edmModel.SchemaElements.OfType <IEdmEnumType>().Single(e => e.Name == "Color");
            IEdmComplexType addressType  = edmModel.SchemaElements.OfType <IEdmComplexType>().Single(e => e.Name == "Address");

            // an enum object
            EdmEnumObject color = new EdmEnumObject(colorType, "Red");

            // a complex object
            EdmComplexObject address1 = new EdmComplexObject(addressType);

            address1.TrySetPropertyValue("Street", "ZiXing Rd");                                            // Declared property
            address1.TrySetPropertyValue("StringProperty", "CN");                                           // a string dynamic property
            address1.TrySetPropertyValue("GuidProperty", new Guid("181D3A20-B41A-489F-9F15-F91F0F6C9ECA")); // a guid dynamic property

            // another complex object with complex dynamic property
            EdmComplexObject address2 = new EdmComplexObject(addressType);

            address2.TrySetPropertyValue("Street", "ZiXing Rd");       // Declared property
            address2.TrySetPropertyValue("AddressProperty", address1); // a complex dynamic property

            // an entity object
            EdmEntityObject customer = new EdmEntityObject(customerType);

            customer.TrySetPropertyValue("CustomerId", 1);      // Declared property
            customer.TrySetPropertyValue("Name", "Mike");       // Declared property
            customer.TrySetPropertyValue("Color", color);       // an enum dynamic property
            customer.TrySetPropertyValue("Address1", address1); // a complex dynamic property
            customer.TrySetPropertyValue("Address2", address2); // another complex dynamic property

            // a collection with one object
            EdmEntityObjectCollection collection =
                new EdmEntityObjectCollection(
                    new EdmCollectionTypeReference(
                        new EdmCollectionType(new EdmEntityTypeReference(customerType, isNullable: true))));

            collection.Add(customer);

            return(collection);
        }
        public static bool TryCreateInstance(Type collectionType, IEdmCollectionTypeReference edmCollectionType, Type elementType, out IEnumerable instance)
        {
            Contract.Assert(collectionType != null);

            if (collectionType == typeof(EdmComplexObjectCollection))
            {
                instance = new EdmComplexObjectCollection(edmCollectionType);
                return true;
            }
            else if (collectionType == typeof(EdmEntityObjectCollection))
            {
                instance = new EdmEntityObjectCollection(edmCollectionType);
                return true;
            }
            else if (collectionType.IsGenericType)
            {
                Type genericDefinition = collectionType.GetGenericTypeDefinition();
                if (genericDefinition == typeof(IEnumerable<>) ||
                    genericDefinition == typeof(ICollection<>) ||
                    genericDefinition == typeof(IList<>))
                {
                    instance = Activator.CreateInstance(typeof(List<>).MakeGenericType(elementType)) as IEnumerable;
                    return true;
                }
            }

            if (collectionType.IsArray)
            {
                // We dont know the size of the collection in advance. So, create a list and later call ToArray. 
                instance = Activator.CreateInstance(typeof(List<>).MakeGenericType(elementType)) as IEnumerable;
                return true;
            }

            if (collectionType.GetConstructor(Type.EmptyTypes) != null && !collectionType.IsAbstract)
            {
                instance = Activator.CreateInstance(collectionType) as IEnumerable;
                return true;
            }

            instance = null;
            return false;
        }
Exemplo n.º 34
0
        public async Task <ActionResult <IEnumerable <IEdmEntityObject> > > Get()
        {
            var entityType     = _oDataRequestHelper.GetEdmEntityTypeReference(Request);
            var collectionType = _oDataRequestHelper.GetEdmCollectionType(Request);

            var collection      = new EdmEntityObjectCollection(new EdmCollectionTypeReference(collectionType));
            var queryCollection = new List <Dictionary <string, object> >();
            var modelSettings   = _oDataModelSettingsProvider.GetEdmModelSettingsFromRequest(Request);
            var entities        = _genericEntityRepository.GetEntities(modelSettings.RouteName);

            foreach (var entity in entities)
            {
                var dynamicEntityDictionary = entity.PropertyList;
                collection.Add(GetEdmEntityObject(dynamicEntityDictionary, entityType));
                queryCollection.Add(dynamicEntityDictionary);
            }
            var result = _oDataFilterManager.ApplyFilter(collection, queryCollection, Request);

            return(Ok(result));
        }
Exemplo n.º 35
0
        public ODataQueryBenchmarks()
        {
            BeforeEachBenchmark(recordCount);
            _url = "https://localhost:44312/odata/entities/user?$apply=groupby((Title),aggregate(Salary with max as MaxSalary))";
            SetRequestHost(new Uri(_url));
            var request        = _httpContext.Request;
            var entityType     = _oDataRequestHelper.GetEdmEntityTypeReference(request);
            var collectionType = _oDataRequestHelper.GetEdmCollectionType(request);

            edmEntityObjectCollection = new EdmEntityObjectCollection(new EdmCollectionTypeReference(collectionType));
            queryCollection           = new List <Dictionary <string, object> >();
            var entities = _genericEntityRepository.GetEntities("user");

            foreach (var entity in entities)
            {
                var dynamicEntityDictionary = entity.PropertyList;
                edmEntityObjectCollection.Add(GetEdmEntityObject(dynamicEntityDictionary, entityType));
                queryCollection.Add(dynamicEntityDictionary);
            }
            _oDataFilterManager = GetODataFilterManager();
        }
Exemplo n.º 36
0
        private static void BuildPeople(IEdmModel model)
        {
            IEdmEntityType personType = model.SchemaElements.OfType <IEdmEntityType>().First(e => e.Name == "Person");

            IEdmEntityObject[] untypedPeople = new IEdmEntityObject[5];
            for (int i = 0; i < 5; i++)
            {
                dynamic untypedPerson = new EdmEntityObject(personType);
                untypedPerson.ID             = i;
                untypedPerson.Country_Region = new[] { "CountryRegion1", "China", "United States", "Russia", "Japan" }[i];
                untypedPerson.Passport       = new[] { "1001", "2010", "9999", "3199992", "00001" }[i];
                untypedPeople[i]             = untypedPerson;
            }

            IEdmCollectionTypeReference entityCollectionType =
                new EdmCollectionTypeReference(
                    new EdmCollectionType(
                        new EdmEntityTypeReference(personType, isNullable: false)));

            People = new EdmEntityObjectCollection(entityCollectionType, untypedPeople.ToList());
        }
Exemplo n.º 37
0
        private static void BuildCompanies(IEdmModel model)
        {
            IEdmEntityType companyType = model.SchemaElements.OfType <IEdmEntityType>().First(e => e.Name == "Company");

            IList <IEdmComplexObject> addresses = BuildAddrsses(model);

            IEdmEntityObject[] untypedCompanies = new IEdmEntityObject[5];
            for (int i = 0; i < 5; i++)
            {
                dynamic untypedCompany = new EdmEntityObject(companyType);
                untypedCompany.ID       = i;
                untypedCompany.Location = addresses[i];
                untypedCompanies[i]     = untypedCompany;
            }

            IEdmCollectionTypeReference entityCollectionType =
                new EdmCollectionTypeReference(
                    new EdmCollectionType(
                        new EdmEntityTypeReference(companyType, isNullable: false)));

            Companies = new EdmEntityObjectCollection(entityCollectionType, untypedCompanies.ToList());
        }
Exemplo n.º 38
0
        // Get entityset
        public IActionResult Get()
        {
            if (!IsCurrentUserAuthorized())
            {
                return(Unauthorized());
            }

            // Get entity set's EDM type: A collection type.
            ODataPath               path           = Request.ODataFeature().Path;
            IEdmCollectionType      collectionType = (IEdmCollectionType)path.EdmType;
            IEdmEntityTypeReference entityType     = collectionType.ElementType.AsEntity();

            // Create an untyped collection with the EDM collection type.
            EdmEntityObjectCollection collection =
                new EdmEntityObjectCollection(new EdmCollectionTypeReference(collectionType));

            var dataSource = GetDataSource();

            new DataSourceProvider(dataSource).Get(BuildQueryOptions(), entityType, collection);

            return(Ok(collection));
        }
        public override object Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)
        {
            if (messageReader == null)
            {
                throw Error.ArgumentNull("messageReader");
            }

            IEdmAction action = GetAction(readContext);
            Contract.Assert(action != null);

            // Create the correct resource type;
            Dictionary<string, object> payload;
            if (type == typeof(ODataActionParameters))
            {
                payload = new ODataActionParameters();
            }
            else
            {
                payload = new ODataUntypedActionParameters(action);
            }

            ODataParameterReader reader = messageReader.CreateODataParameterReader(action);

            while (reader.Read())
            {
                string parameterName = null;
                IEdmOperationParameter parameter = null;

                switch (reader.State)
                {
                    case ODataParameterReaderState.Value:
                        parameterName = reader.Name;
                        parameter = action.Parameters.SingleOrDefault(p => p.Name == parameterName);
                        // ODataLib protects against this but asserting just in case.
                        Contract.Assert(parameter != null, String.Format(CultureInfo.InvariantCulture, "Parameter '{0}' not found.", parameterName));
                        if (parameter.Type.IsPrimitive())
                        {
                            payload[parameterName] = reader.Value;
                        }
                        else
                        {
                            ODataEdmTypeDeserializer deserializer = DeserializerProvider.GetEdmTypeDeserializer(parameter.Type);
                            payload[parameterName] = deserializer.ReadInline(reader.Value, parameter.Type, readContext);
                        }
                        break;

                    case ODataParameterReaderState.Collection:
                        parameterName = reader.Name;
                        parameter = action.Parameters.SingleOrDefault(p => p.Name == parameterName);
                        // ODataLib protects against this but asserting just in case.
                        Contract.Assert(parameter != null, String.Format(CultureInfo.InvariantCulture, "Parameter '{0}' not found.", parameterName));
                        IEdmCollectionTypeReference collectionType = parameter.Type as IEdmCollectionTypeReference;
                        Contract.Assert(collectionType != null);
                        ODataCollectionValue value = ODataCollectionDeserializer.ReadCollection(reader.CreateCollectionReader());
                        ODataCollectionDeserializer collectionDeserializer = (ODataCollectionDeserializer)DeserializerProvider.GetEdmTypeDeserializer(collectionType);
                        payload[parameterName] = collectionDeserializer.ReadInline(value, collectionType, readContext);
                        break;

                    case ODataParameterReaderState.Entry:
                        parameterName = reader.Name;
                        parameter = action.Parameters.SingleOrDefault(p => p.Name == parameterName);
                        Contract.Assert(parameter != null, String.Format(CultureInfo.InvariantCulture, "Parameter '{0}' not found.", parameterName));

                        IEdmEntityTypeReference entityTypeReference = parameter.Type as IEdmEntityTypeReference;
                        Contract.Assert(entityTypeReference != null);

                        ODataReader entryReader = reader.CreateEntryReader();
                        object item = ODataEntityDeserializer.ReadEntryOrFeed(entryReader);
                        ODataEntityDeserializer entityDeserializer = (ODataEntityDeserializer)DeserializerProvider.GetEdmTypeDeserializer(entityTypeReference);
                        payload[parameterName] = entityDeserializer.ReadInline(item, entityTypeReference, readContext);
                        break;

                    case ODataParameterReaderState.Feed:
                        parameterName = reader.Name;
                        parameter = action.Parameters.SingleOrDefault(p => p.Name == parameterName);
                        Contract.Assert(parameter != null, String.Format(CultureInfo.InvariantCulture, "Parameter '{0}' not found.", parameterName));

                        IEdmCollectionTypeReference feedType = parameter.Type as IEdmCollectionTypeReference;
                        Contract.Assert(feedType != null);

                        ODataReader feedReader = reader.CreateFeedReader();
                        object feed = ODataEntityDeserializer.ReadEntryOrFeed(feedReader);
                        ODataFeedDeserializer feedDeserializer = (ODataFeedDeserializer)DeserializerProvider.GetEdmTypeDeserializer(feedType);

                        object result = feedDeserializer.ReadInline(feed, feedType, readContext);

                        IEdmTypeReference elementTypeReference = feedType.ElementType();
                        Contract.Assert(elementTypeReference.IsEntity());

                        IEnumerable enumerable = result as IEnumerable;
                        if (enumerable != null)
                        {
                            if (readContext.IsUntyped)
                            {
                                EdmEntityObjectCollection entityCollection = new EdmEntityObjectCollection(feedType);
                                foreach (EdmEntityObject entityObject in enumerable)
                                {
                                    entityCollection.Add(entityObject);
                                }

                                payload[parameterName] = entityCollection;
                            }
                            else
                            {
                                Type elementClrType = EdmLibHelpers.GetClrType(elementTypeReference, readContext.Model);
                                IEnumerable castedResult =
                                    _castMethodInfo.MakeGenericMethod(elementClrType)
                                        .Invoke(null, new[] { result }) as IEnumerable;
                                payload[parameterName] = castedResult;
                            }
                        }
                        break;
                }
            }

            return payload;
        }
Exemplo n.º 40
0
        private static EdmEntityObjectCollection GetCustomers()
        {
            if (_untypedSimpleOpenCustormers != null)
            {
                return _untypedSimpleOpenCustormers;
            }
            EdmEntityType customerType = new EdmEntityType("NS", "UntypedSimpleOpenCustomer", null, false, true);
            customerType.AddKeys(customerType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32));
            EdmEntityObject customer = new EdmEntityObject(customerType);
            customer.TrySetPropertyValue("CustomerId", 1);

            //Add Numbers primitive collection property
            customer.TrySetPropertyValue("DeclaredNumbers", new[] { 1, 2 });

            //Add Color, Colors enum(collection) property
            EdmEnumType colorType = new EdmEnumType("NS", "Color");
            colorType.AddMember(new EdmEnumMember(colorType, "Red", new EdmIntegerConstant(0)));

            EdmEnumObject color = new EdmEnumObject(colorType, "Red");
            EdmEnumObject color2 = new EdmEnumObject(colorType, "0");
            EdmEnumObject color3 = new EdmEnumObject(colorType, "Red");
            customer.TrySetPropertyValue("Color", color);

            List<IEdmEnumObject> colorList = new List<IEdmEnumObject>();
            colorList.Add(color);
            colorList.Add(color2);
            colorList.Add(color3);
            IEdmCollectionTypeReference enumCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(colorType.ToEdmTypeReference(false)));
            EdmEnumObjectCollection colors = new EdmEnumObjectCollection(enumCollectionType, colorList);
            customer.TrySetPropertyValue("Colors", colors);
            customer.TrySetPropertyValue("DeclaredColors", colors);

            //Add Addresses complex(collection) property 
            EdmComplexType addressType = new EdmComplexType("NS", "Address", null, false, true);
            addressType.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);

            EdmComplexObject address = new EdmComplexObject(addressType);
            address.TrySetPropertyValue("Street", "No1");
            EdmComplexObject address2 = new EdmComplexObject(addressType);
            address2.TrySetPropertyValue("Street", "No2");

            List<IEdmComplexObject> addressList = new List<IEdmComplexObject>();
            addressList.Add(address);
            addressList.Add(address2);
            IEdmCollectionTypeReference complexCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(addressType.ToEdmTypeReference(false)));
            EdmComplexObjectCollection addresses = new EdmComplexObjectCollection(complexCollectionType, addressList);
            customer.TrySetPropertyValue("DeclaredAddresses", addresses);

            EdmEntityObjectCollection customers = new EdmEntityObjectCollection(new EdmCollectionTypeReference(new EdmCollectionType(customerType.ToEdmTypeReference(false))));
            customers.Add(customer);
            _untypedSimpleOpenCustormers = customers;
            return _untypedSimpleOpenCustormers;
        }
Exemplo n.º 41
0
        public IHttpActionResult Get()
        {
            IEdmModel model = Request.ODataProperties().Model;
            IEdmEntityType customerType = model.SchemaElements.OfType<IEdmEntityType>().First(e => e.Name == "Customer");

            EdmEntityObject customer = new EdmEntityObject(customerType);

            customer.TrySetPropertyValue("Id", 1);
            customer.TrySetPropertyValue("Tony", 1);

            EdmEntityObjectCollection customers =
                new EdmEntityObjectCollection(
                    new EdmCollectionTypeReference(new EdmCollectionType(customerType.ToEdmTypeReference(false))));
            customers.Add(customer);
            return Ok(customers);

        }
            internal static object ConvertFeed(ODataMessageReader oDataMessageReader, IEdmTypeReference edmTypeReference, ODataDeserializerContext readContext)
            {
                IEdmCollectionTypeReference collectionType = edmTypeReference.AsCollection();

                EdmEntitySet tempEntitySet = new EdmEntitySet(readContext.Model.EntityContainer, "temp",
                    collectionType.ElementType().AsEntity().EntityDefinition());

                ODataReader odataReader = oDataMessageReader.CreateODataFeedReader(tempEntitySet,
                    collectionType.ElementType().AsEntity().EntityDefinition());
                ODataFeedWithEntries feed =
                    ODataEntityDeserializer.ReadEntryOrFeed(odataReader) as ODataFeedWithEntries;

                ODataFeedDeserializer feedDeserializer =
                    (ODataFeedDeserializer)DeserializerProvider.GetEdmTypeDeserializer(collectionType);

                object result = feedDeserializer.ReadInline(feed, collectionType, readContext);
                IEnumerable enumerable = result as IEnumerable;
                if (enumerable != null)
                {
                    IEnumerable newEnumerable = CovertFeedIds(enumerable, feed, collectionType, readContext);
                    if (readContext.IsUntyped)
                    {
                        EdmEntityObjectCollection entityCollection =
                            new EdmEntityObjectCollection(collectionType);
                        foreach (EdmEntityObject entity in newEnumerable)
                        {
                            entityCollection.Add(entity);
                        }

                        return entityCollection;
                    }
                    else
                    {
                        IEdmTypeReference elementTypeReference = collectionType.ElementType();

                        Type elementClrType = EdmLibHelpers.GetClrType(elementTypeReference,
                            readContext.Model);
                        IEnumerable castedResult =
                            CastMethodInfo.MakeGenericMethod(elementClrType)
                                .Invoke(null, new object[] { newEnumerable }) as IEnumerable;
                        return castedResult;
                    }
                }

                return null;
            }
 private dynamic CreateOrders(int i)
 {
     EdmEntityObject[] orders = new EdmEntityObject[i];
     for (int j = 0; j < i; j++)
     {
         dynamic order = new EdmEntityObject(OrderType);
         order.Id = j;
         order.ShippingAddress = CreateAddress(j);
         orders[j] = order;
     }
     var collection = new EdmEntityObjectCollection(new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(OrderType, false))), orders);
     return collection;
 }
Exemplo n.º 44
0
        EdmEntityObjectCollection Get(IEdmCollectionType edmType, string sqlCmd, List<ExpandedNavigationSelectItem> expands = null)
        {
            var entityType = edmType.ElementType.AsEntity();

            EdmEntityObjectCollection collection = new EdmEntityObjectCollection(new EdmCollectionTypeReference(edmType));
            using (DbAccess db = new DbAccess(this.ConnectionString))
            {
                db.ExecuteReader(sqlCmd, (reader) =>
                {
                    EdmEntityObject entity = new EdmEntityObject(entityType);
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        reader.SetEntityPropertyValue(i, entity);
                    }
                    if (expands != null)
                    {
                        foreach (var expanded in expands)
                        {
                            List<string> condition = new List<string>();
                            foreach (NavigationPropertySegment item in expanded.PathToNavigationProperty)
                            {
                                foreach (var p in item.NavigationProperty.ReferentialConstraint.PropertyPairs)
                                {
                                    condition.Add(packCondition(p, reader[p.DependentProperty.Name]));
                                }
                            }
                            var ss = Get(expanded.NavigationSource.Type as IEdmCollectionType, BuildSqlQueryCmd(expanded, string.Join(" and ", condition)));
                            bool t = entity.TrySetPropertyValue(expanded.NavigationSource.Name, ss);
                        }
                    }
                    collection.Add(entity);

                }, null, CommandType.Text);
            }
            return collection;
        }
        private static void BuildCompanies(IEdmModel model)
        {
            IEdmEntityType companyType = model.SchemaElements.OfType<IEdmEntityType>().First(e => e.Name == "Company");

            IList<IEdmComplexObject> addresses = BuildAddrsses(model);

            IEdmEntityObject[] untypedCompanies = new IEdmEntityObject[5];
            for (int i = 0; i < 5; i++)
            {
                dynamic untypedCompany = new EdmEntityObject(companyType);
                untypedCompany.ID = i;
                untypedCompany.Location = addresses[i];
                untypedCompanies[i] = untypedCompany;
            }

            IEdmCollectionTypeReference entityCollectionType =
                new EdmCollectionTypeReference(
                    new EdmCollectionType(
                        new EdmEntityTypeReference(companyType, isNullable: false)));

            Companies = new EdmEntityObjectCollection(entityCollectionType, untypedCompanies.ToList());
        }
        private static void BuildPeople(IEdmModel model)
        {
            IEdmEntityType personType = model.SchemaElements.OfType<IEdmEntityType>().First(e => e.Name == "Person");

            IEdmEntityObject[] untypedPeople = new IEdmEntityObject[5];
            for (int i = 0; i < 5; i++)
            {
                dynamic untypedPerson = new EdmEntityObject(personType);
                untypedPerson.ID = i;
                untypedPerson.Country = new[] { "Great Britain", "China", "United States", "Russia", "Japan" }[i];
                untypedPerson.Passport = new[] { "1001", "2010", "9999", "3199992", "00001"}[i];
                untypedPeople[i] = untypedPerson;
            }

            IEdmCollectionTypeReference entityCollectionType =
                new EdmCollectionTypeReference(
                    new EdmCollectionType(
                        new EdmEntityTypeReference(personType, isNullable: false)));

            People = new EdmEntityObjectCollection(entityCollectionType, untypedPeople.ToList());
        }
        private static void BuildOrderss(IEdmModel model)
        {
            IEdmEntityType orderType = model.SchemaElements.OfType<IEdmEntityType>().First(e => e.Name == "Order");

            Guid[] guids =
            {
                new Guid("196B3584-EF3D-41FD-90B4-76D59F9B929C"),
                new Guid("6CED5600-28BA-40EE-A2DF-E80AFADBE6C7"),
                new Guid("75036B94-C836-4946-8CC8-054CF54060EC"),
                new Guid("B3FF5460-6E77-4678-B959-DCC1C4937FA7"),
                new Guid("ED773C85-4E3C-4FC4-A3E9-9F1DA0A626DA")
            };

            IEdmEntityObject[] untypedOrders = new IEdmEntityObject[5];
            for (int i = 0; i < 5; i++)
            {
                dynamic untypedOrder = new EdmEntityObject(orderType);
                untypedOrder.OrderId = i;
                untypedOrder.Name = string.Format("Order-{0}", i);
                untypedOrder.Token = guids[i];
                untypedOrder.Amount = 10 + i;
                untypedOrders[i] = untypedOrder;
            }

            IEdmCollectionTypeReference entityCollectionType =
                new EdmCollectionTypeReference(
                    new EdmCollectionType(
                        new EdmEntityTypeReference(orderType, isNullable: false)));

            Orders = new EdmEntityObjectCollection(entityCollectionType, untypedOrders.ToList());
        }