public void PrefetchViaReferenceToSelfTest() { Key key; using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { var referenceToSelf = new ReferenceToSelf { AuxField = 100 }; key = referenceToSelf.Key; referenceToSelf.Reference = referenceToSelf; tx.Complete(); } using (var session = Domain.OpenSession()) using (session.OpenTransaction()) { var prefetchManager = (PrefetchManager)PrefetchProcessorField.GetValue(session.Handler); var referenceField = Domain.Model.Types[typeof(ReferenceToSelf)].Fields["Reference"]; prefetchManager.InvokePrefetch(key, null, new PrefetchFieldDescriptor(referenceField, true, true)); prefetchManager.ExecuteTasks(true); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(key, key.TypeInfo, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); PrefetchTestHelper.AssertReferencedEntityIsLoaded(key, session, referenceField); } }
public void ReferenceToSelfPrefetchTest() { TypeInfo referenceToSelfType; var keys = new List <Key>(); using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { referenceToSelfType = Domain.Model.Types[typeof(ReferenceToSelf)]; var reference = new ReferenceToSelf { AuxField = 3 }; keys.Add(reference.Key); reference.Reference = reference; reference = new ReferenceToSelf { AuxField = 5 }; keys.Add(Key.Create(Domain, typeof(IReferenceToSelf), reference.Key.Value)); reference.Reference = reference; tx.Complete(); } using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { session.Query.Many <IReferenceToSelf>(keys) .Prefetch(r => r.Reference) .Run(); foreach (var key in keys) { PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(key, referenceToSelfType, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); } } }
public void ParseRefenceToSelf() { var source = new ReferenceToSelf(); source.Self = source; var target = Parse(source); var self = target["Self"]; Assert.That(target, Is.SameAs(self)); }