Beispiel #1
0
        public void QueryMultiValueProperty()
        {
            var writeRequest = new GoogleData.BlindWriteRequest();

            var entity = new GoogleData.Entity();
            entity.Key = new GoogleData.Key();
            entity.Key.Path = new List<KeyPathElement>();
            entity.Key.Path.Add(new GoogleData.KeyPathElement { Kind = "CodeProse.Pogo.Tests.TestPerson", Name = "TestMultiValueQuery" });
            entity.Properties = new GoogleData.Entity.PropertiesData();

            var skills = new GoogleData.Property { Multi = true };
            skills.Values = new List<GoogleData.Value>();
            skills.Values.Add(new GoogleData.Value { StringValue = ".NET" });
            skills.Values.Add(new GoogleData.Value { StringValue = "Pogo" });
            skills.Values.Add(new GoogleData.Value { StringValue = "Google Cloud Datastore" });
            entity.Properties.Add("Skills", skills);

            writeRequest.Mutation = new GoogleData.Mutation();
            writeRequest.Mutation.Upsert = new List<GoogleData.Entity>();
            writeRequest.Mutation.Upsert.Add(entity);

            var response = _service.Datasets.BlindWrite(writeRequest, _datasetId).Fetch();

            var query = new Query();
            query.Kinds = new List<KindExpression> { new KindExpression { Name = "CodeProse.Pogo.Tests.TestPerson" } };

            query.Filter = new Filter
            {
                PropertyFilter = new PropertyFilter
                    {
                        Operator = "equal",
                        Value = new Value { StringValue = "Pogo" },
                        Property = new PropertyReference { Name = "Skills" }
                    }
            };

            var queryRequest = new RunQueryRequest { Query = query };
            var queryResponse = _service.Datasets.RunQuery(queryRequest, _datasetId).Fetch();

            Assert.IsTrue(queryResponse.Batch.EntityResults[0].Entity.Properties["Skills"].Values.Count > 1);
        }