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); } }
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); } }
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); } }