Пример #1
0
        public void ParentChildReference_CustomId_Example()
        {
            var cn = TestHelper.CreateConnection();

            using (var session = new SimoSession(cn))
            {
                var entityStore = new SimoEntityStore(session, DbName);

                //This time we use anonymous type and custom Id's (Guids).
                var parent          = new { _id = Guid.NewGuid(), Name = "Daniel" };
                var fatherReference = entityStore.Reference("Parent", parent._id);
                var child           = new { _id = Guid.NewGuid(), 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<Guid> { CollectionName = "Parents", Id = parent._id };

                entityStore.Insert("Parent", parent);
                entityStore.Insert("Child", child);

                var refetchedChild = entityStore.FindOneInfered(child, entityName: "Child", selector: new { child._id });

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

                //This time we use anonymous type and custom Id's (Guids).
                var parent = new { _id = Guid.NewGuid(), Name = "Daniel" };
                var fatherReference = entityStore.Reference("Parent", parent._id);
                var child = new { _id = Guid.NewGuid(), 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<Guid> { CollectionName = "Parents", Id = parent._id };

                entityStore.Insert("Parent", parent);
                entityStore.Insert("Child", child);

                var refetchedChild = entityStore.FindOneInfered(child, entityName: "Child", selector: new { child._id });

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