Пример #1
0
        public void NewRelation_UsingStaticTypes_ReferenceCreated()
        {
            var parent = new Parent { Name = "Daniel" };
            var fatherReference = new SimoReference { CollectionName = Constants.Collections.ParentsCollectionName, Id = parent._id };
            var child = new Child { Name = "Isabell", FatherReference = fatherReference };
            TestHelper.InsertDocument(Constants.Collections.ParentsFullCollectionName, parent);
            TestHelper.InsertDocument(Constants.Collections.ChildsFullCollectionName, child);

            var refetchedChild = TestHelper.GetDocument<Child>(new { child._id }, Constants.Collections.ChildsFullCollectionName);

            Assert.AreEqual(fatherReference.Id, refetchedChild.FatherReference.Id);
            Assert.AreEqual(fatherReference.CollectionName, refetchedChild.FatherReference.CollectionName);
        }
Пример #2
0
        public void ParentChildReference_Example()
        {
            var cn = TestHelper.CreateConnection();
            using (var session = new SimoSession(cn))
            {
                var entityStore = new SimoEntityStore(session, DbName);

                //The parent generates a new _id when created.
                //That _id is then used in the reference which is attached to the child.
                //After that, you just store the items.
                var parent = new Parent { Name = "Daniel" };
                var fatherReference = entityStore.Reference<Parent>(parent._id);
                var child = new Child { Name = "Isabell", FatherReference = fatherReference };

                //You could of course have created the reference manually, but then you loose the
                //use of the pluralizer, and have to role-this on your own.
                //new SimoReference { CollectionName = "Parents", Id = parent._id };

                entityStore.Insert(parent);
                entityStore.Insert(child);

                var refetchedChild = entityStore.FindOne<Child>(new { child._id });

                Assert.AreEqual(fatherReference.Id, refetchedChild.FatherReference.Id);
                Assert.AreEqual(fatherReference.CollectionName, refetchedChild.FatherReference.CollectionName);
            }
        }