Пример #1
0
        static LCRelation <LCObject> DecodeRelation(IDictionary dict)
        {
            LCRelation <LCObject> relation = new LCRelation <LCObject>();

            relation.TargetClass = dict["className"].ToString();
            return(relation);
        }
        public object Apply(object oldValue, string key)
        {
            LCRelation <LCObject> relation = new LCRelation <LCObject>();

            relation.TargetClass = valueList[0].ClassName;
            return(relation);
        }
Пример #3
0
 static object EncodeRelation(LCRelation <LCObject> relation)
 {
     return(new Dictionary <string, object> {
         { "__type", "Relation" },
         { "className", relation.TargetClass }
     });
 }
Пример #4
0
        public async Task AddAndRemove()
        {
            LCObject parent = new LCObject("Parent");
            LCObject c1     = new LCObject("Child");

            parent.AddRelation("children", c1);
            LCObject c2 = new LCObject("Child");

            parent.AddRelation("children", c2);
            await parent.Save();

            LCRelation <LCObject> relation = parent["children"] as LCRelation <LCObject>;
            LCQuery <LCObject>    query    = relation.Query;
            int count = await query.Count();

            TestContext.WriteLine($"count: {count}");
            Assert.AreEqual(count, 2);

            parent.RemoveRelation("children", c2);
            await parent.Save();

            int count2 = await query.Count();

            TestContext.WriteLine($"count: {count2}");
            Assert.AreEqual(count2, 1);
        }
Пример #5
0
        public async Task Query()
        {
            LCQuery <LCObject> query  = new LCQuery <LCObject>("Parent");
            LCObject           parent = await query.Get("5e13112021b47e0070ed0922");

            LCRelation <LCObject> relation = parent["children"] as LCRelation <LCObject>;

            TestContext.WriteLine(relation.Key);
            TestContext.WriteLine(relation.Parent);
            TestContext.WriteLine(relation.TargetClass);

            Assert.NotNull(relation.Key);
            Assert.NotNull(relation.Parent);
            Assert.NotNull(relation.TargetClass);

            LCQuery <LCObject> relationQuery = relation.Query;
            List <LCObject>    list          = await relationQuery.Find();

            list.ForEach(item => {
                TestContext.WriteLine(item.ObjectId);
                Assert.NotNull(item.ObjectId);
            });
        }
Пример #6
0
        public async Task Query()
        {
            LCQuery <LCObject> query       = new LCQuery <LCObject>("Parent");
            LCObject           queryParent = await query.Get(parent.ObjectId);

            LCRelation <LCObject> relation = queryParent["children"] as LCRelation <LCObject>;

            TestContext.WriteLine(relation.Key);
            TestContext.WriteLine(relation.Parent);
            TestContext.WriteLine(relation.TargetClass);

            Assert.NotNull(relation.Key);
            Assert.NotNull(relation.Parent);
            Assert.NotNull(relation.TargetClass);

            LCQuery <LCObject>            relationQuery = relation.Query;
            ReadOnlyCollection <LCObject> results       = await relationQuery.Find();

            foreach (LCObject item in results)
            {
                TestContext.WriteLine(item.ObjectId);
                Assert.NotNull(item.ObjectId);
            }
        }