예제 #1
0
        public void TestDeleteBulkObjects_OpResult()
        {
            List <Person> personList   = new List <Person>();
            Person        firstPerson  = new Person();
            Person        secondPerson = new Person();

            firstPerson.age   = 22;
            firstPerson.name  = "John";
            secondPerson.age  = 12;
            secondPerson.name = "Ivie";
            personList.Add(firstPerson);
            personList.Add(secondPerson);

            UnitOfWork uow = new UnitOfWork();

            DataQueryBuilder queryBuilder = DataQueryBuilder.Create();

            queryBuilder.SetWhereClause("age > '10'");

            OpResult invalidName = uow.Find("Person", queryBuilder);

            uow.BulkDelete(invalidName);

            UnitOfWorkResult uowResult = uow.Execute();

            Assert.IsTrue(uowResult.Success);
            Assert.IsNotNull(uowResult.Results);

            IList <Person> listCheckPerson = Backendless.Data.Of <Person>().Find();

            Assert.IsTrue(listCheckPerson.Count == 0);
        }
예제 #2
0
        // -------------------------------------------------------
        // 自定义查询条件
        // -------------------------------------------------------

        #region 属性:BuildWhereClause(DataQuery query)
        /// <summary>根据场景名称构建查询条件</summary>
        /// <param name="query"></param>
        /// <returns></returns>
        private string BuildWhereClause(DataQuery query)
        {
            string whereClause = string.Empty;

            string scence = query.Variables["scence"];

            if (string.IsNullOrEmpty(scence))
            {
                // 默认查询方式
                whereClause = query.GetWhereSql(new Dictionary <string, string>()
                {
                    { "AttachmentName", "LIKE" }
                });
            }
            else
            {
                StringBuilder outString = new StringBuilder();

                if (scence == "Query")
                {
                    DataQueryBuilder.Equal(query.Where, "id", outString);
                    DataQueryBuilder.Equal(query.Where, "attachmentName", outString);
                    DataQueryBuilder.Equal(query.Where, "entityId", outString);

                    DataQueryBuilder.Between(query.Where, "createdDate", "beginDate", "endDate", outString);

                    return(outString.ToString());
                }
            }

            return(whereClause);
        }
예제 #3
0
        public async Task <IEnumerable <Acquaintance> > GetItems()
        {
            await EnsureDataIsSeededAsync();

            DataQueryBuilder queryBuilder = DataQueryBuilder.Create();

            queryBuilder.SetPageSize(100);
            queryBuilder.SetWhereClause($"DataPartitionId = '{_DataPartitionId}'");
            List <String> sortByList = new List <string>();

            sortByList.Add("LastName");
            queryBuilder.SetSortBy(sortByList);

            IList <Acquaintance> items = await Backendless.Data.Of <Acquaintance>().FindAsync(queryBuilder);

            if (items.Count == 0)
            {
                Settings.DataIsSeeded = false;
                await EnsureDataIsSeededAsync();

                return(await GetItems());
            }

            return(items);
        }
예제 #4
0
        public int GetObjectCount <T>(DataQueryBuilder dataQueryBuilder)
        {
            BackendlessDataQuery dataQuery = dataQueryBuilder.Build();

            return(Invoker.InvokeSync <int>(PERSISTENCE_MANAGER_SERVER_ALIAS, "count",
                                            new object[] { GetTypeName(typeof(T)), dataQuery }, true));
        }
예제 #5
0
        public void TestPersistenceServiceFindById_Dictionary()
        {
            List <Dictionary <String, Object> > listPerson = new List <Dictionary <String, Object> >();
            Dictionary <String, Object>         person     = new Dictionary <String, Object>();

            person["age"]  = 15;
            person["name"] = "Alexandra";

            List <String> listId = new List <String>();

            listPerson.Add(person);
            listId = (List <String>)Backendless.Data.Of("Person").Create(listPerson);

            person["objectId"] = listId[0];
            DataQueryBuilder queryBuilder = DataQueryBuilder.Create();

            queryBuilder.AddProperties("age");
            Dictionary <String, Object> result = Backendless.Data.Of("Person").FindById(person, queryBuilder);

            Assert.IsNotNull(result);
            Assert.AreEqual(result["objectId"], listId[0], "Object id were not equivalent");
            Assert.IsFalse(result.ContainsKey("name"));
            Assert.IsTrue(result.ContainsKey("age"));

            Backendless.Data.Of("Person").Remove("age = '15'");
        }
예제 #6
0
        public void TestFindWithMissingProperties()
        {
            RunAndAwait(() =>
            {
                var findWithPropertiesEntity = new FindWithPropertiesEntityAsync {
                    Name = "bot_#foobar", Age = 20
                };
                Backendless.Persistence.Save(findWithPropertiesEntity,
                                             new ResponseCallback <FindWithPropertiesEntityAsync>(this)
                {
                    ResponseHandler = response =>
                    {
                        var dataQueryBuilder = DataQueryBuilder.Create().AddProperty("foobar");

                        Backendless.Persistence.Of <FindWithPropertiesEntityAsync>()
                        .Find(dataQueryBuilder,
                              new AsyncCallback
                              <IList <FindWithPropertiesEntityAsync> >
                                  (collection =>
                                  Assert.Fail("Server didn't throw an exception"),
                                  fault => CheckErrorCode(1006, fault)));
                    }
                });
            });
        }
        /// <summary>查询所有相关记录</summary>
        /// <param name="query">数据查询参数</param>
        /// <returns>返回所有实例<see cref="ApplicationMenuInfo"/>的详细信息</returns>
        public IList <ApplicationMenuInfo> FindAll(DataQuery query)
        {
            Dictionary <string, object> args = new Dictionary <string, object>();

            StringBuilder whereClause = new StringBuilder();

            if (query.Variables["scence"] == "Search")
            {
                // query.Where.Add("AppKey", appKey);
                // query.Where.Add("Code", bankCodes);

                whereClause.Append(" Status = 5 ");

                if (query.Where.ContainsKey("AppKey") && query.Where.ContainsKey("Code"))
                {
                    if (query.Where["Code"].ToString() == "0")
                    {
                        DataQueryBuilder.Equal(query.Where, "AppKey", whereClause);
                    }
                    else
                    {
                        query.Where["Code"] = "'" + query.Where["Code"].ToString().Replace(",", "','") + "'";

                        DataQueryBuilder.Equal(query.Where, "AppKey", whereClause);
                        DataQueryBuilder.In(query.Where, "Code", whereClause);
                    }
                }
                else if (query.Where.ContainsKey("Id"))
                {
                    if (query.Where["Id"].ToString() == "0")
                    {
                        // =0 返回全库
                    }
                    else
                    {
                        DataQueryBuilder.In(query.Where, "Id", whereClause);
                    }
                }

                args.Add("WhereClause", whereClause);
            }
            else
            {
                args.Add("WhereClause", query.GetWhereSql(new Dictionary <string, string>()
                {
                    { "Name", "LIKE" }
                }));
            }

            args.Add("OrderBy", query.GetOrderBySql(" Id DESC "));
            args.Add("Length", query.Length);

            // 普通用户只能看到授权范围内的内容
            if (!AppsSecurity.IsAdministrator(KernelContext.Current.User, AppsConfiguration.ApplicationName) && !AppsSecurity.IsReviewer(KernelContext.Current.User, AppsConfiguration.ApplicationName))
            {
                args["WhereClause"] = this.BindAuthorizationScopeSQL((string)args["WhereClause"]);
            }

            return(this.ibatisMapper.QueryForList <ApplicationMenuInfo>(StringHelper.ToProcedurePrefix(string.Format("{0}_FindAll", tableName)), args));
        }
예제 #8
0
        public void TestPersistenceServiceFindById_StringId_Async()
        {
            List <Dictionary <String, Object> > listPerson = new List <Dictionary <String, Object> >();
            Dictionary <String, Object>         person     = new Dictionary <String, Object>();

            person["age"]  = 15;
            person["name"] = "Alexandra";

            List <String> listId = new List <String>();

            listPerson.Add(person);
            listId = (List <String>)Backendless.Data.Of("Person").Create(listPerson);

            DataQueryBuilder queryBuilder = DataQueryBuilder.Create();

            queryBuilder.AddProperties("age");
            Backendless.Data.Of("Person").FindById(listId[0], queryBuilder, new AsyncCallback <Dictionary <String, Object> >(
                                                       callback =>
            {
                Assert.IsNotNull(callback);
                Assert.AreEqual(callback["objectId"], listId[0], "Object id were not equivalent");
                Assert.IsFalse(callback.ContainsKey("name"));
                Assert.IsTrue(callback.ContainsKey("age"));
            },
                                                       fault =>
            {
                throw new ArgumentException("Error");
            }));

            Backendless.Data.Of("Person").Remove("age = '15'");
        }
        public void TestDeleteSingleObject_OpResult()
        {
            List <Person> personList   = new List <Person>();
            Person        personObject = new Person();

            personObject.name = "Bob";
            personObject.age  = 23;
            personList.Add(personObject);
            String objectId = Backendless.Data.Of <Person>().Create(personList)[0];

            UnitOfWork uow = new UnitOfWork();

            DataQueryBuilder queryBuilder = DataQueryBuilder.Create();

            queryBuilder.SetWhereClause("age = '23'");

            OpResult opResult = uow.Find("Person", queryBuilder);
            OpResultValueReference firstInvalid = opResult.ResolveTo(0);

            uow.Delete(firstInvalid);

            UnitOfWorkResult uowResult = uow.Execute();

            Assert.IsTrue(uowResult.Success);
            Assert.IsNotNull(uowResult.Results);

            IList <Person> listCheckPerson = Backendless.Data.Of <Person>().Find();

            Assert.IsTrue(listCheckPerson.Count == 0);
        }
예제 #10
0
        public void Find(DataQueryBuilder dataQueryBuilder, AsyncCallback <IList <Dictionary <String, Object> > > callback)
        {
            var responder = new AsyncCallback <IList <Dictionary <String, Object> > >(
                r =>
            {
                if (callback != null)
                {
                    callback.ResponseHandler.Invoke(r);
                }
            },
                f =>
            {
                if (callback != null)
                {
                    callback.ErrorHandler.Invoke(f);
                }
                else
                {
                    throw new BackendlessException(f);
                }
            });

            if (dataQueryBuilder == null)
            {
                dataQueryBuilder = DataQueryBuilder.Create();
            }

            BackendlessDataQuery dataQuery = dataQueryBuilder.Build();

            Object[] args = { tableName, dataQuery };
            Invoker.InvokeAsync(PERSISTENCE_MANAGER_SERVER_ALIAS, "find", args, responder);
        }
예제 #11
0
        async Task EnsureDataIsSeededAsync()
        {
            if (Settings.DataIsSeeded)
            {
                return;
            }

            int count = 0;

            try
            {
                await Backendless.Data.Of <Acquaintance>().GetObjectCountAsync(DataQueryBuilder.Create().SetWhereClause($"DataPartitionId = '{_DataPartitionId}'"));
            }
            catch (Exception)
            {
            }

            if (count > 0)
            {
                Settings.DataIsSeeded = true;
            }

            if (!Settings.DataIsSeeded)
            {
                var newItems = SeedData.Get(_DataPartitionId);

                await Backendless.Data.Of <Acquaintance>().CreateAsync(newItems);

                Settings.DataIsSeeded = true;
            }
        }
예제 #12
0
        public Int32 GetObjectCount(DataQueryBuilder dataQueryBuilder)
        {
            BackendlessDataQuery dataQuery = dataQueryBuilder.Build();

            return(Invoker.InvokeSync <Int32>(PERSISTENCE_MANAGER_SERVER_ALIAS, "count", new Object[] { tableName, dataQuery },
                                              true));
        }
예제 #13
0
        public void GetObjectCount(DataQueryBuilder dataQueryBuilder, AsyncCallback <Int32> responder)
        {
            BackendlessDataQuery dataQuery = dataQueryBuilder.Build();

            Invoker.InvokeAsync <Int32>(PERSISTENCE_MANAGER_SERVER_ALIAS, "count", new Object[] { tableName, dataQuery }, true,
                                        responder);
        }
예제 #14
0
        public void TestFind_AllObjects()
        {
            List <Person> listPerson     = new List <Person>();
            Person        personCreated1 = new Person();

            personCreated1.age  = 17;
            personCreated1.name = "Alexandra";

            Person personCreated2 = new Person();

            personCreated2.age  = 24;
            personCreated2.name = "Joe";

            listPerson.Add(personCreated1);
            listPerson.Add(personCreated2);
            IList <String> objectIds = Backendless.Data.Of <Person>().Create(listPerson);

            UnitOfWork uow = new UnitOfWork();
            OpResult   opResultCreateBulkPerson = uow.BulkCreate(listPerson);
            OpResult   opResultFindPerson       = uow.Find("Person", DataQueryBuilder.Create());

            UnitOfWorkResult uowResult = uow.Execute();

            Assert.IsTrue(uowResult.Success);
            Dictionary <String, OperationResult> results = uowResult.Results;

            Assert.IsTrue(2 == results.Count);

            Dictionary <Object, Object>[] resultFind = (Dictionary <Object, Object>[])results[opResultFindPerson.OpResultId].Result;
            Assert.IsTrue(4 == resultFind.Length);

            Backendless.Data.Of("Person").Remove("age > '15'");
        }
예제 #15
0
        public void Find <T>(DataQueryBuilder dataQueryBuilder, AsyncCallback <IList <T> > callback)
        {
            var responder = new AsyncCallback <IList <T> >(r =>
            {
                if (callback != null)
                {
                    callback.ResponseHandler.Invoke(r);
                }
            }, f =>
            {
                if (callback != null)
                {
                    callback.ErrorHandler.Invoke(f);
                }
                else
                {
                    throw new BackendlessException(f);
                }
            });

            BackendlessDataQuery dataQuery = dataQueryBuilder != null?dataQueryBuilder.Build() : null;

            AddWeborbPropertyMapping <T>();
            Invoker.InvokeAsync(PERSISTENCE_MANAGER_SERVER_ALIAS, "find",
                                new object[] { GetTypeName(typeof(T)), dataQuery },
                                true,
                                responder);
        }
예제 #16
0
        public void TestCollectionGetPage()
        {
            var getPageEntities = new List <GetPageEntity>();

            for (int i = 10; i < 30; i++)
            {
                var entity = new GetPageEntity {
                    Name = "name#" + i, Age = 20 + i
                };
                Backendless.Persistence.Save(entity);

                if (i > 19 && i < 30)
                {
                    getPageEntities.Add(entity);
                }

                Thread.Sleep(1000);
            }

            var dataQueryBuilder = DataQueryBuilder.Create().AddProperty("Age").SetPageSize(10);
            var collection       = Backendless.Persistence.Of <GetPageEntity>().Find(dataQueryBuilder.PrepareNextPage());

            Assert.IsNotNull(collection, "Next page returned a null object");
            Assert.AreEqual(getPageEntities.Count, collection.Count, "Next page returned a wrong size");

            foreach (GetPageEntity entity in getPageEntities)
            {
                Assert.IsTrue(collection.Contains(entity), "Server result didn't contain expected entity");
            }
        }
예제 #17
0
        public void TestCollectionGetPage()
        {
            RunAndAwait(() =>
            {
                var getPageEntities = new List <GetPageEntityAsync>();
                var latch           = new CountdownEvent(20);
                for (int i = 10; i < 30; i++)
                {
                    var entity = new GetPageEntityAsync {
                        Name = "name#" + i, Age = 20 + i
                    };
                    Backendless.Persistence.Save(entity,
                                                 new AsyncCallback <GetPageEntityAsync>(response => latch.Signal(), fault =>
                    {
                        for (int j = 0; j < latch.CurrentCount; j++)
                        {
                            latch.Signal();
                        }
                    }));

                    if (i > 19 && i < 30)
                    {
                        getPageEntities.Add(entity);
                    }
                }
                latch.Wait();

                var dataQueryBuilder = DataQueryBuilder.Create().AddProperty("Age").SetPageSize(10).SetOffset(0);
                Backendless.Persistence.Of <GetPageEntityAsync>()
                .Find(dataQueryBuilder,
                      new ResponseCallback <IList <GetPageEntityAsync> >(this)
                {
                    ResponseHandler =
                        response =>
                        Backendless.Persistence.Of <GetPageEntityAsync>().Find(dataQueryBuilder.PrepareNextPage(),
                                                                               new ResponseCallback <IList <GetPageEntityAsync> >(this)
                    {
                        ResponseHandler = collection =>
                        {
                            Assert.IsNotNull(collection, "Next page returned a null object");
                            Assert.AreEqual(getPageEntities.Count,
                                            collection.Count,
                                            "Next page returned a wrong size");

                            foreach (GetPageEntityAsync entity in getPageEntities)
                            {
                                Assert.IsTrue(
                                    collection.Contains(entity),
                                    "Server result didn't contain expected entity");
                            }

                            CountDown();
                        }
                    })
                });
            });
        }
예제 #18
0
        public IList <T> Find <T>(DataQueryBuilder dataQueryBuilder)
        {
            BackendlessDataQuery dataQuery = dataQueryBuilder != null?dataQueryBuilder.Build() : null;

            AddWeborbPropertyMapping <T>();
            var result = Invoker.InvokeSync <IList <T> >(PERSISTENCE_MANAGER_SERVER_ALIAS, "find",
                                                         new object[] { GetTypeName(typeof(T)), dataQuery }, true);

            return((IList <T>)result);
        }
예제 #19
0
        public void TestWhereClauseZero()
        {
            DataQueryBuilder qb = DataQueryBuilder.Create();

            qb.AddAllProperties();
            qb.SetWhereClause("name='Joe'");
            IList <Dictionary <String, Object> > res = Backendless.Data.Of("Orders").Find(qb);

            Assert.IsTrue(res.Count == 0);
        }
예제 #20
0
        public void TestFind_CheckError()
        {
            UnitOfWork uow = new UnitOfWork();

            uow.Find("Wrong table name", DataQueryBuilder.Create());
            UnitOfWorkResult uowResult = uow.Execute();

            Assert.IsFalse(uowResult.Success);
            Assert.IsNull(uowResult.Results);
        }
예제 #21
0
        public void TestAddRelation_OpResult()
        {
            List <Person> listPerson = new List <Person>();
            Person        personObj  = new Person();

            personObj.age  = 22;
            personObj.name = "Eva";
            listPerson.Add(personObj);

            IList <String> parentObjIds = Backendless.Data.Of <Person>().Create(listPerson);

            listPerson.Clear();
            personObj.objectId = parentObjIds[0];

            List <Order> listOrder = new List <Order>();
            Order        orderObj  = new Order();

            orderObj.LastName = "Smith";
            listOrder.Add(orderObj);
            List <Dictionary <String, Object> > listChildObjMap = new List <Dictionary <String, Object> >();
            Dictionary <String, Object>         childObjMap     = new Dictionary <String, Object>();

            childObjMap["LastName"] = "Smith";
            listChildObjMap.Add(childObjMap);

            IList <String> childObjIds = Backendless.Data.Of("Order").Create(listChildObjMap);

            listChildObjMap.Clear();
            childObjMap["objectId"] = childObjIds[0];
            listChildObjMap.Add(childObjMap);

            UnitOfWork uow = new UnitOfWork();

            DataQueryBuilder queryBuilder = DataQueryBuilder.Create();

            queryBuilder.SetWhereClause("LastName in ('Smith')");

            OpResult gifts          = uow.Find("Order", queryBuilder);
            String   relationColumn = "Surname";

            uow.AddToRelation(personObj.GetType().Name, personObj.objectId, relationColumn, gifts);
            UnitOfWorkResult uowResult = uow.Execute();

            Assert.IsTrue(uowResult.Success);
            Assert.IsNotNull(uowResult.Results);

            DataQueryBuilder dqb = DataQueryBuilder.Create();

            dqb.SetRelationsPageSize(10);
            dqb.SetRelationsDepth(10);
            IList <Person> listCheckPersonObj = Backendless.Data.Of <Person>().Find(dqb);

            Assert.IsTrue(listCheckPersonObj.Count == 1);
            Assert.IsTrue(listCheckPersonObj[0].Surname != null);
        }
        public void TestDeleteRelation_Dictionary()
        {
            List <Dictionary <String, Object> > listObjMap = new List <Dictionary <String, Object> >();
            Dictionary <String, Object>         parentObj  = new Dictionary <String, Object>();
            Dictionary <String, Object>         childObj   = new Dictionary <String, Object>();

            parentObj["name"] = "Eva";
            parentObj["age"]  = 22;

            childObj["LastName"] = "Smith";
            listObjMap.Add(parentObj);

            IList <String> parentId = Backendless.Data.Of("Person").Create(listObjMap);

            parentObj["objectId"] = parentId[0];
            listObjMap.Clear();
            listObjMap.Add(childObj);

            List <String> childId = (List <String>)Backendless.Data.Of("Order").Create(listObjMap);

            listObjMap.Clear();
            childObj["objectId"] = childId[0];
            listObjMap.Add(childObj);

            String relationColumnName = "Surname";

            Backendless.Data.Of("Person").AddRelation(parentObj, relationColumnName, listObjMap.ToArray());

            DataQueryBuilder dqb = DataQueryBuilder.Create();

            dqb.SetRelationsDepth(10);
            dqb.SetRelationsPageSize(10);

            IList <Dictionary <String, Object> > objectBefore_DeleteRelation = Backendless.Data.Of("Person").Find(dqb);

            Assert.IsTrue(objectBefore_DeleteRelation[0]["Surname"] != null);

            listObjMap.Clear();
            childObj["objectId"] = childId[0];
            listObjMap.Add(childObj);

            UnitOfWork uow = new UnitOfWork();

            uow.DeleteRelation("Person", parentId[0], relationColumnName, listObjMap);

            UnitOfWorkResult uowResult = uow.Execute();

            Assert.IsTrue(uowResult.Success);
            Assert.IsNotNull(uowResult.Results);

            IList <Dictionary <String, Object> > objectAfter_DeleteRelation = Backendless.Data.Of("Person").Find(dqb);

            Assert.IsNull(objectAfter_DeleteRelation[0]["Surname"]);
        }
        public static DataQueryBuilder BackendlessDataQueryToDataQueryBuilder(BackendlessDataQuery dataQuery)
        {
            DataQueryBuilder dataQueryBuilder = DataQueryBuilder.Create();

            if (!string.IsNullOrEmpty(dataQuery.WhereClause))
            {
                dataQueryBuilder.SetWhereClause(dataQuery.WhereClause);
            }

            if (dataQuery.Offset > 0)
            {
                dataQueryBuilder.SetOffset(dataQuery.Offset);
            }

            if (dataQuery.PageSize > 0)
            {
                dataQueryBuilder.SetPageSize(dataQuery.PageSize);
            }

            if (dataQuery.Properties != null)
            {
                dataQueryBuilder.SetProperties(dataQuery.Properties);
            }

            if (dataQuery.QueryOptions != null)
            {
                if (dataQuery.QueryOptions.Offset > 0)
                {
                    dataQueryBuilder.SetOffset(dataQuery.QueryOptions.Offset);
                }

                if (dataQuery.QueryOptions.PageSize > 0)
                {
                    dataQueryBuilder.SetPageSize(dataQuery.QueryOptions.PageSize);
                }

                if (dataQuery.QueryOptions.Related != null)
                {
                    dataQueryBuilder.SetRelated(dataQuery.QueryOptions.Related);
                }

                if (dataQuery.QueryOptions.RelationsDepth > 0)
                {
                    dataQueryBuilder.SetRelationsDepth(dataQuery.QueryOptions.RelationsDepth);
                }

                if (dataQuery.QueryOptions.SortBy != null)
                {
                    dataQueryBuilder.SetSortBy(dataQuery.QueryOptions.SortBy);
                }
            }

            return(dataQueryBuilder);
        }
예제 #24
0
        public void TestCreateFieldTIME()
        {
            DataQueryBuilder queryBuilder = DataQueryBuilder.Create();

            queryBuilder.AddProperties("*", "TIME(created) as myTime");

            IList <Dictionary <String, Object> > res = Backendless.Data.Of("Person").Find(queryBuilder);

            Assert.IsTrue(res[0].ContainsKey("myTime"), "First object does not contain 'myTime' key");
            Assert.IsTrue(res[1].ContainsKey("myTime"), "Second object does not contain 'myTime' key");
        }
예제 #25
0
        public OpResult Find(String tableName, DataQueryBuilder queryBuilder)
        {
            BackendlessDataQuery query = queryBuilder.Build();

            String        operationResultId = opResultIdGenerator.GenerateOpResultId(OperationType.FIND, tableName);
            OperationFind operationFind     = new OperationFind(OperationType.FIND, tableName, operationResultId, query);

            operations.AddLast(operationFind);

            return(TransactionHelper.MakeOpResult(tableName, operationResultId, OperationType.FIND));
        }
예제 #26
0
        public void TestRelatedField()
        {
            DataQueryBuilder queryBuilder = DataQueryBuilder.Create();

            queryBuilder.AddProperties("*", "Location.adress");

            IList <Dictionary <String, Object> > res = Backendless.Data.Of("Person").Find(queryBuilder);

            Assert.IsTrue(res[0].ContainsKey("adress"), "First object does not contain 'adress' field");
            Assert.IsTrue(res[1].ContainsKey("adress"), "Second object does not contain 'adress' field");
        }
예제 #27
0
        public void TestRelationsWithClass()
        {
            DataQueryBuilder qb = DataQueryBuilder.Create();

            qb.AddAllProperties();
            qb.SetRelated(new List <String> {
                "Related"
            });
            IList <Orders> res = Backendless.Data.Of <Orders>().Find(qb);

            Assert.IsTrue(res[0].Related.Count == 1);
        }
예제 #28
0
 public static async Task <IList <Dictionary <String, Object> > > FindWithSortAsync(String tableName, String sortBy)
 {
     try
     {
         return(await Backendless.Data.Of($"{tableName}")
                .FindAsync(DataQueryBuilder.Create().AddSortBy(sortBy)));
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
예제 #29
0
        public void TestSetRelation_Dictionary()
        {
            List <Dictionary <String, Object> > listMaps  = new List <Dictionary <String, Object> >();
            Dictionary <String, Object>         objectMap = new Dictionary <String, Object>();

            objectMap["age"]  = 22;
            objectMap["name"] = "Eva";
            listMaps.Add(objectMap);

            IList <String> parentObjIds = Backendless.Data.Of("Person").Create(listMaps);

            listMaps.Clear();
            objectMap["objectId"] = parentObjIds[0];

            List <Order> listOrder = new List <Order>();
            Order        orderObj  = new Order();

            orderObj.LastName = "Smith";
            listOrder.Add(orderObj);
            List <Dictionary <String, Object> > listChildObjMap = new List <Dictionary <String, Object> >();
            Dictionary <String, Object>         childObjMap     = new Dictionary <String, Object>();

            childObjMap["LastName"] = "Smith";
            listChildObjMap.Add(childObjMap);



            IList <String> childObjIds = Backendless.Data.Of("Order").Create(listChildObjMap);

            listChildObjMap.Clear();
            childObjMap["objectId"] = childObjIds[0];
            listChildObjMap.Add(childObjMap);

            String relationColumn = "Surname";

            UnitOfWork uow = new UnitOfWork();

            uow.SetRelation("Person", objectMap, relationColumn, childObjIds.ToArray());
            UnitOfWorkResult uowResult = uow.Execute();

            Assert.IsTrue(uowResult.Success);
            Assert.IsNotNull(uowResult.Results);

            DataQueryBuilder dqb = DataQueryBuilder.Create();

            dqb.SetRelationsPageSize(10);
            dqb.SetRelationsDepth(10);
            IList <Person> listCheckPersonObj = Backendless.Data.Of <Person>().Find(dqb);

            Assert.IsTrue(listCheckPersonObj.Count == 1);
            Assert.IsTrue(listCheckPersonObj[0].Surname != null);
        }
        public void TestDeleteRelation_OpResult()
        {
            List <Person> listObjects  = new List <Person>();
            Person        personObject = new Person();

            personObject.age  = 22;
            personObject.name = "Jia";
            listObjects.Add(personObject);

            List <Order> childObject = new List <Order>();
            Order        orderObject = new Order();

            orderObject.LastName = "Smith";

            personObject.objectId = Backendless.Data.Of <Person>().Create(listObjects)[0];

            childObject.Add(orderObject);
            orderObject.objectId = Backendless.Data.Of <Order>().Create(childObject)[0];

            childObject.Clear();
            childObject.Add(orderObject);

            String relationColumn = "Surname";

            Backendless.Data.Of <Person>().AddRelation(personObject, relationColumn, childObject.ToArray());

            DataQueryBuilder dqb = DataQueryBuilder.Create();

            dqb.SetRelationsDepth(10);
            dqb.SetRelationsPageSize(10);

            IList <Dictionary <String, Object> > objectBefore_DeleteRelation = Backendless.Data.Of("Person").Find(dqb);

            Assert.IsTrue(objectBefore_DeleteRelation[0]["Surname"] != null);

            DataQueryBuilder queryBuilder = DataQueryBuilder.Create();

            queryBuilder.SetWhereClause("LastName in ('Smith')");

            UnitOfWork uow   = new UnitOfWork();
            OpResult   gifts = uow.Find("Order", queryBuilder);

            uow.DeleteRelation(personObject.GetType().Name, personObject.objectId, relationColumn, gifts);
            UnitOfWorkResult uowResult = uow.Execute();

            Assert.IsTrue(uowResult.Success);
            Assert.IsNotNull(uowResult.Results);

            IList <Dictionary <String, Object> > objectAfter_DeleteRelation = Backendless.Data.Of("Person").Find(dqb);

            Assert.IsNull(objectAfter_DeleteRelation[0]["Surname"]);
        }