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); }
public void FindOne_ChildHasNullReferenceToParent_ReturnsChildWithNullReferenceParent() { var child = new Child { Name = "Isabell" }; TestHelper.InsertDocument(Constants.Collections.ChildsCollectionName, child); var cn = TestHelper.CreateConnection(); using (var session = new SimoSession(cn)) { var entityStore = new SimoEntityStore(session, DbName); var refetchedChild = entityStore.FindOne<Child>(new { _id = child._id }); Assert.IsNotNull(refetchedChild, "Couldn't refetch child."); Assert.IsNull(refetchedChild.FatherReference, "Fatherreference should be null."); } }
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); } }