public void CanUpdateNonLazyWithoutLoadingLazyProperty() { Book book; using (ISession s = OpenSession()) using (var trans = s.BeginTransaction()) { book = s.Get <Book>(1); book.Name += "updated"; book.FieldInterceptor += "updated"; Assert.That(NHibernateUtil.IsPropertyInitialized(book, "ALotOfText"), Is.False, "Before flush and commit"); trans.Commit(); Assert.That(NHibernateUtil.IsPropertyInitialized(book, "ALotOfText"), Is.False, "After flush and commit"); } using (ISession s = OpenSession()) { book = s.Get <Book>(1); Assert.That(book.Name, Is.EqualTo("some nameupdated")); Assert.That(book.FieldInterceptor, Is.EqualTo("Why not that name?updated")); } }
public async Task LazyUpdateTestAsync() { using (var s = OpenSession()) using (var t = s.BeginTransaction()) { var p = await(s.CreateQuery("from Person p where name='Gabor'").UniqueResultAsync <Person>()); // make sure component has not been initialized yet Assert.That(!NHibernateUtil.IsPropertyInitialized(p, "Address")); p.Address.City = "Baja"; await(s.UpdateAsync(p)); await(t.CommitAsync()); } using (var s = OpenSession()) using (var t = s.BeginTransaction()) { var p = await(s.CreateQuery("from Person p where name='Gabor'").UniqueResultAsync <Person>()); Assert.That(p.Address.City, Is.EqualTo("Baja")); await(t.CommitAsync()); } }
public void TestGroups() { using (var s = OpenSession()) { var person = s.Get <Person>(1); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Name"), Is.True); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "NickName"), Is.False); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Address"), Is.False); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Image"), Is.False); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Age"), Is.False); var nickName = person.NickName; Assert.That(NHibernateUtil.IsPropertyInitialized(person, "NickName"), Is.True); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Address"), Is.False); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Image"), Is.False); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Age"), Is.False); Assert.That(nickName, Is.EqualTo("NickName1")); var address = person.Address; Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Address"), Is.True); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Image"), Is.False); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Age"), Is.False); Assert.That(address.City, Is.EqualTo("City1")); Assert.That(address.Street, Is.EqualTo("Street1")); Assert.That(address.PostCode, Is.EqualTo(1001)); var image = person.Image; Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Image"), Is.True); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Age"), Is.False); Assert.That(person.Image, Has.Length.EqualTo(1)); var age = person.Age; Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Age"), Is.True); Assert.That(person.Age, Is.EqualTo(1)); } }
public async Task WhenGetThenLoadOnlyNoLazyPlainPropertiesAsync() { using (ISession s = OpenSession()) { Order order; using (var ls = new SqlLogSpy()) { order = await(s.GetAsync <Order>(1)); var logMessage = ls.GetWholeLog(); Assert.That(logMessage, Does.Not.Contain("ALazyProperty")); Assert.That(logMessage, Does.Contain("NoLazyProperty")); } Assert.That(NHibernateUtil.IsPropertyInitialized(order, "NoLazyProperty"), Is.True); Assert.That(NHibernateUtil.IsPropertyInitialized(order, "ALazyProperty"), Is.False); using (var ls = new SqlLogSpy()) { var x = order.ALazyProperty; var logMessage = ls.GetWholeLog(); Assert.That(logMessage, Does.Contain("ALazyProperty")); } Assert.That(NHibernateUtil.IsPropertyInitialized(order, "ALazyProperty"), Is.True); } }
public async Task SelectModeFetchLazyPropertiesForEntityJoinAsync() { using (var sqlLog = new SqlLogSpy()) using (var session = OpenSession()) { EntityComplex parentJoin = null; EntitySimpleChild rootChild = null; rootChild = await(session.QueryOver(() => rootChild) .JoinEntityQueryOver(() => parentJoin, Restrictions.Where(() => rootChild.ParentId == parentJoin.Id)) .Fetch(SelectMode.FetchLazyProperties, ec => ec) .Take(1) .SingleOrDefaultAsync()); parentJoin = await(session.LoadAsync <EntityComplex>(rootChild.ParentId)); Assert.That(rootChild, Is.Not.Null); Assert.That(NHibernateUtil.IsInitialized(rootChild), Is.True); Assert.That(NHibernateUtil.IsInitialized(parentJoin), Is.True); Assert.That(NHibernateUtil.IsPropertyInitialized(parentJoin, nameof(parentJoin.LazyProp)), Is.Not.Null.Or.Empty); Assert.That(parentJoin.LazyProp, Is.Not.Null.Or.Empty); Assert.That(sqlLog.Appender.GetEvents().Length, Is.EqualTo(1), "Only one SQL select is expected"); } }
public async Task TestFetchComponentCacheAsync() { Person person; using (var s = OpenSession()) using (var tx = s.BeginTransaction()) { person = await(s.Query <Person>().Fetch(o => o.Address).FirstOrDefaultAsync(o => o.Id == 1)); AssertFetchComponent(person); await(tx.CommitAsync()); } using (var s = OpenSession()) using (var tx = s.BeginTransaction()) { person = await(s.GetAsync <Person>(1)); AssertFetchComponent(person); // Will reset the cache item person.Name = "Test"; await(tx.CommitAsync()); } using (var s = OpenSession()) using (var tx = s.BeginTransaction()) { person = await(s.GetAsync <Person>(1)); Assert.That(person, Is.Not.Null); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Image"), Is.False); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Address"), Is.False); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Formula"), Is.False); await(tx.CommitAsync()); } }
private static void AssertFetchOneToManyProperty(Person person) { Assert.That(person, Is.Not.Null); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Image"), Is.False); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Address"), Is.False); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Formula"), Is.False); Assert.That(NHibernateUtil.IsInitialized(person.BestFriend), Is.False); Assert.That(NHibernateUtil.IsInitialized(person.Pets), Is.False); Assert.That(NHibernateUtil.IsInitialized(person.Cats), Is.True); Assert.That(person.Cats, Has.Count.EqualTo(1)); foreach (var cat in person.Cats) { Assert.That(NHibernateUtil.IsPropertyInitialized(cat, "Image"), Is.False); Assert.That(NHibernateUtil.IsPropertyInitialized(cat, "Formula"), Is.False); Assert.That(NHibernateUtil.IsPropertyInitialized(cat, "Address"), Is.False); Assert.That(NHibernateUtil.IsPropertyInitialized(cat, "SecondImage"), Is.True); Assert.That(NHibernateUtil.IsPropertyInitialized(cat, "SecondFormula"), Is.False); Assert.That(cat.SecondImage, Has.Length.EqualTo(6)); } }
private static void AssertFetchFormulaAndOneToManyComponent(Person person) { Assert.That(person, Is.Not.Null); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Image"), Is.False); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Address"), Is.False); Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Formula"), Is.True); Assert.That(NHibernateUtil.IsInitialized(person.Dogs), Is.True); Assert.That(NHibernateUtil.IsInitialized(person.BestFriend), Is.False); Assert.That(NHibernateUtil.IsInitialized(person.Pets), Is.False); Assert.That(person.Formula, Is.EqualTo(1)); Assert.That(person.Dogs, Has.Count.EqualTo(1)); foreach (var dog in person.Dogs) { Assert.That(NHibernateUtil.IsPropertyInitialized(dog, "Image"), Is.False); Assert.That(NHibernateUtil.IsPropertyInitialized(dog, "Formula"), Is.False); Assert.That(NHibernateUtil.IsPropertyInitialized(dog, "Address"), Is.True); Assert.That(dog.Address.City, Is.EqualTo("City1")); Assert.That(dog.Address.Country, Is.EqualTo("Country1")); } }
public void WhenGetThenLoadOnlyNoLazyPlainProperties() { using (ISession s = OpenSession()) { Order order; using (var ls = new SqlLogSpy()) { order = s.Get <Order>(1); var logMessage = ls.GetWholeLog(); logMessage.Should().Not.Contain("ALazyProperty"); logMessage.Should().Contain("NoLazyProperty"); } order.Satisfy(o => NHibernateUtil.IsPropertyInitialized(o, "NoLazyProperty")); order.Satisfy(o => !NHibernateUtil.IsPropertyInitialized(o, "ALazyProperty")); using (var ls = new SqlLogSpy()) { var x = order.ALazyProperty; var logMessage = ls.GetWholeLog(); logMessage.Should().Contain("ALazyProperty"); } order.Satisfy(o => NHibernateUtil.IsPropertyInitialized(o, "ALazyProperty")); } }
public async Task LazyPropertyShouldBeUninitializedAndLoadableAsync() { using (var session = OpenSession()) using (var tran = session.BeginTransaction()) { var e1 = await(session.Query <CompositeEntity>().SingleAsync()); Assert.Multiple( () => { Assert.That( NHibernateUtil.IsPropertyInitialized(e1, nameof(CompositeEntity.LazyProperty)), Is.False, "Lazy property initialization status"); Assert.That( e1 is IFieldInterceptorAccessor, Is.True, "Entity IsInstrumented"); Assert.That( e1, Has.Property(nameof(CompositeEntity.LazyProperty)).EqualTo("LazyProperty")); }); await(tran.CommitAsync()); } }
public void LazyPropertyShouldBeUninitializedAndLoadableWithComponentId() { using (var session = OpenSession()) using (var tran = session.BeginTransaction()) { var e2 = session.Query <EntityWithComponentId>().Single(); Assert.Multiple( () => { Assert.That( NHibernateUtil.IsPropertyInitialized(e2, nameof(CompositeEntity.LazyProperty)), Is.False, "Lazy property initialization status"); Assert.That( e2 is IFieldInterceptorAccessor, Is.True, "Entity IsInstrumented"); Assert.That( e2, Has.Property(nameof(CompositeEntity.LazyProperty)).EqualTo("LazyProperty")); }); tran.Commit(); } }
public void WhenGetThenLoadOnlyNoLazyPlainProperties() { using (ISession s = OpenSession()) { Order order; using (var ls = new SqlLogSpy()) { order = s.Get <Order>(1); var logMessage = ls.GetWholeLog(); Assert.That(logMessage, Is.Not.StringContaining("ALazyProperty")); Assert.That(logMessage, Is.StringContaining("NoLazyProperty")); } Assert.That(NHibernateUtil.IsPropertyInitialized(order, "NoLazyProperty"), Is.True); Assert.That(NHibernateUtil.IsPropertyInitialized(order, "ALazyProperty"), Is.False); using (var ls = new SqlLogSpy()) { var x = order.ALazyProperty; var logMessage = ls.GetWholeLog(); Assert.That(logMessage, Is.StringContaining("ALazyProperty")); } Assert.That(NHibernateUtil.IsPropertyInitialized(order, "ALazyProperty"), Is.True); } }
private static object DeepClone(this ISessionImplementor session, object entity, DeepCloneOptions opts, System.Type entityType, IDictionary <object, object> resolvedEntities, DeepCloneParentEntity parentEntity = null) { opts = opts ?? new DeepCloneOptions(); if (entity == null || !NHibernateUtil.IsInitialized(entity)) { return(entityType.GetDefaultValue()); } entityType = entityType ?? entity.GetUnproxiedType(true); if (entityType.IsSimpleType()) { return(entity); } AbstractEntityPersister entityMetadata; try { entityMetadata = (AbstractEntityPersister)session.Factory.GetClassMetadata(entityType); } catch (Exception) { return(entityType.GetDefaultValue()); } if (resolvedEntities.ContainsKey(entity) && parentEntity != null) { return(CopyOnlyForeignKeyProperties(resolvedEntities[entity], entityType, entityMetadata, opts, parentEntity)); } if (resolvedEntities.ContainsKey(entity)) { return(resolvedEntities[entity]); } if (opts.CanCloneAsReferenceFunc != null && opts.CanCloneAsReferenceFunc(entityType)) { return(entity); } var propertyInfos = entityType.GetProperties(); var copiedEntity = ReflectHelper.GetDefaultConstructor(entityType).Invoke(new object[0]); resolvedEntities.Add(entity, copiedEntity); foreach (var propertyInfo in propertyInfos .Where(p => opts.CanCloneIdentifier(entityType) || entityMetadata.IdentifierPropertyName != p.Name) .Where(p => !opts.GetIgnoreMembers(entityType).Contains(p.Name)) .Where(p => p.GetSetMethod(true) != null)) { IType propertyType; try { propertyType = entityMetadata.GetPropertyType(propertyInfo.Name); } catch (Exception) { continue; } var resolveFn = opts.GetResolveFunction(entityType, propertyInfo.Name); if (resolveFn != null) { propertyInfo.SetValue(copiedEntity, resolveFn(entity), null); continue; } if (propertyType.IsEntityType && opts.SkipEntityTypesValue.HasValue && opts.SkipEntityTypesValue.Value) { continue; } //TODO: verify: false only when entity is a proxy or lazy field/property that is not yet initialized if (!NHibernateUtil.IsPropertyInitialized(entity, propertyInfo.Name)) { continue; } var propertyValue = propertyInfo.GetValue(entity, null); if (!NHibernateUtil.IsInitialized(propertyValue)) { //Use session load for proxy, works only for references (collections are not supported) if ( propertyValue != null && propertyValue.IsProxy() && !(propertyValue is IPersistentCollection) && opts.UseSessionLoadFunction ) { var lazyInit = ((INHibernateProxy)propertyValue).HibernateLazyInitializer; propertyInfo.SetValue(copiedEntity, LoadEntity(session, lazyInit.PersistentClass, lazyInit.Identifier), null); } continue; } var filterFn = opts.GetFilterFunction(entityType, propertyInfo.Name); if (filterFn != null) { propertyValue = filterFn(propertyValue); } var colNames = entityMetadata.GetPropertyColumnNames(propertyInfo.Name); var propType = propertyInfo.PropertyType; var copyAsReference = opts.CanCloneAsReference(entityType, propertyInfo.Name); if (propertyType.IsCollectionType) { var propertyList = CreateNewCollection(propertyType); propertyInfo.SetValue(copiedEntity, propertyList, null); AddItemToCollection(propertyList, propertyValue, o => copyAsReference ? o : session.DeepClone(o, opts, null, resolvedEntities, new DeepCloneParentEntity { Entity = copiedEntity, EntityPersister = entityMetadata, ChildType = propertyType, ReferencedColumns = ((CollectionType)propertyType) .GetReferencedColumns(session.Factory) })); } else if (propertyType.IsEntityType) { if (copyAsReference) { propertyInfo.SetValue(copiedEntity, propertyValue, null); } //Check if we have a parent entity and that is bidirectional related to the current property (one-to-many) else if (parentEntity != null && parentEntity.ReferencedColumns.SequenceEqual(colNames)) { propertyInfo.SetValue(copiedEntity, parentEntity.Entity, null); } else { propertyInfo.SetValue(copiedEntity, session.DeepClone(propertyValue, opts, propType, resolvedEntities), null); } } else if (propType.IsSimpleType()) { //Check if we have a parent entity and that is bidirectional related to the current property (one-to-many) //we dont want to set FKs to the parent entity as the parent is cloned if (parentEntity != null && parentEntity.ReferencedColumns.Contains(colNames.First())) { continue; } propertyInfo.SetValue(copiedEntity, propertyValue, null); } } return(copiedEntity); }
public async Task SessionSerializationWithLazyPropertyAsync() { using (var s = OpenSession()) { using (var t = s.BeginTransaction()) { // Get + initialize property var le1 = await(s.GetAsync <LazyTextEntity>(_idLazyTextEntity1)); Assert.That(le1.Text, Is.EqualTo("Text1"), "le1.Text after Get"); Assert.That( NHibernateUtil.IsPropertyInitialized(le1, nameof(LazyTextEntity.Text)), Is.True, "Lazy Text property should be initialized on le1 after reading it"); Assert.That(le1.IsProxy(), Is.False, "le1 should not be a lazy entity proxy"); var ilte1 = await(s.GetAsync <ILazyTextEntity>(_idInterfacedLazyTextEntity1)); Assert.That(ilte1.Text, Is.EqualTo("Text1"), "ilte1.Text after Get"); Assert.That( NHibernateUtil.IsPropertyInitialized(ilte1, nameof(ILazyTextEntity.Text)), Is.True, "Lazy Text property should be initialized on ilte1 after reading it"); Assert.That(ilte1.IsProxy(), Is.False, "ilte1 should not be a lazy entity proxy"); // Just Get var le2 = await(s.GetAsync <LazyTextEntity>(_idLazyTextEntity2)); Assert.That( NHibernateUtil.IsPropertyInitialized(le2, nameof(LazyTextEntity.Text)), Is.False, "Lazy Text property should not be initialized on le2 after Get"); Assert.That(le2.IsProxy(), Is.False, "le2 should not be a lazy entity proxy"); var ilte2 = await(s.GetAsync <ILazyTextEntity>(_idInterfacedLazyTextEntity2)); Assert.That( NHibernateUtil.IsPropertyInitialized(ilte2, nameof(ILazyTextEntity.Text)), Is.False, "Lazy Text property should not be initialized on ilte2 after Get"); Assert.That(ilte2.IsProxy(), Is.False, "ilte2 should not be a lazy entity proxy"); // Load + initialize property var le3 = await(s.LoadAsync <LazyTextEntity>(_idLazyTextEntity3)); Assert.That(le3.Text, Is.EqualTo("Text3"), "le3.Text after Load"); Assert.That( NHibernateUtil.IsPropertyInitialized(le3, nameof(LazyTextEntity.Text)), Is.True, "Lazy Text property should be initialized on le3 after reading it"); Assert.That(le3.IsProxy(), Is.True, "le3 should be a lazy entity proxy"); var ilte3 = await(s.LoadAsync <ILazyTextEntity>(_idInterfacedLazyTextEntity3)); Assert.That(ilte3.Text, Is.EqualTo("Text3"), "ilte3.Text after Load"); Assert.That( NHibernateUtil.IsPropertyInitialized(ilte3, nameof(ILazyTextEntity.Text)), Is.True, "Lazy Text property should be initialized on ilte3 after reading it"); Assert.That(ilte3.IsProxy(), Is.True, "ilte3 should be a lazy entity proxy"); // Just Load var le4 = await(s.LoadAsync <LazyTextEntity>(_idLazyTextEntity4)); Assert.That( NHibernateUtil.IsPropertyInitialized(le4, nameof(LazyTextEntity.Text)), Is.False, "Lazy Text property should not be initialized on le4 after Load"); Assert.That( NHibernateUtil.IsInitialized(le4), Is.False, "le4 should not be initialized after checking if a property is initialized"); Assert.That(le4.IsProxy(), Is.True, "le4 should be a lazy entity proxy"); var ilte4 = await(s.LoadAsync <ILazyTextEntity>(_idInterfacedLazyTextEntity4)); Assert.That( NHibernateUtil.IsPropertyInitialized(ilte4, nameof(ILazyTextEntity.Text)), Is.False, "Lazy Text property should not be initialized on ilte4 after Load"); Assert.That( NHibernateUtil.IsInitialized(ilte4), Is.False, "ilte4 should not be initialized after checking if a property is initialized"); Assert.That(ilte4.IsProxy(), Is.True, "ilte4 should be a lazy entity proxy"); // Load + initialize entity proxy var le5 = await(s.LoadAsync <LazyTextEntity>(_idLazyTextEntity5)); Assert.That(le5.Name, Is.EqualTo("5"), "le5.Name after load"); Assert.That( NHibernateUtil.IsPropertyInitialized(le5, nameof(LazyTextEntity.Text)), Is.False, "Lazy Text property should not be initialized on le5 after initializing its proxy"); Assert.That(le5.IsProxy(), Is.True, "le5 should be a lazy entity proxy"); var ilte5 = await(s.LoadAsync <ILazyTextEntity>(_idInterfacedLazyTextEntity5)); Assert.That(ilte5.Name, Is.EqualTo("5"), "ilte5.Name after load"); Assert.That( NHibernateUtil.IsPropertyInitialized(ilte5, nameof(ILazyTextEntity.Text)), Is.False, "Lazy Text property should not be initialized on ilte5 after initializing its proxy"); Assert.That(ilte5.IsProxy(), Is.True, "ilte5 should be a lazy entity proxy"); await(t.CommitAsync()); } var serializer = GetFormatter(); ISession ds; using (var memoryStream = new MemoryStream()) { serializer.Serialize(memoryStream, s); s.Close(); memoryStream.Seek(0L, SeekOrigin.Begin); ds = (ISession)serializer.Deserialize(memoryStream); } try { using (var t = ds.BeginTransaction()) { var le1 = await(ds.LoadAsync <LazyTextEntity>(_idLazyTextEntity1)); Assert.That( NHibernateUtil.IsPropertyInitialized(le1, nameof(LazyTextEntity.Text)), Is.True, "Lazy Text property should be initialized on le1 after deserializing it"); Assert.That(le1.Name, Is.EqualTo("1"), "le1.Name after deserialization"); Assert.That(le1.Text, Is.EqualTo("Text1"), "le1.Text after deserialization"); Assert.That(le1.IsProxy(), Is.False, "le1 should not be a lazy entity proxy after deserializing it"); var ilte1 = await(ds.LoadAsync <ILazyTextEntity>(_idInterfacedLazyTextEntity1)); Assert.That( NHibernateUtil.IsPropertyInitialized(ilte1, nameof(ILazyTextEntity.Text)), Is.True, "Lazy Text property should be initialized on ilte1 after deserializing it"); Assert.That(ilte1.Name, Is.EqualTo("1"), "ilte1.Name after deserialization"); Assert.That(ilte1.Text, Is.EqualTo("Text1"), "ilte1.Text after deserialization"); Assert.That(ilte1.IsProxy(), Is.False, "ilte1 should not be a lazy entity proxy after deserializing it"); var le2 = await(ds.LoadAsync <LazyTextEntity>(_idLazyTextEntity2)); Assert.That( NHibernateUtil.IsInitialized(le2), Is.True, "le2 should be initialized after deserialization"); Assert.That(le2.Name, Is.EqualTo("2"), "le2.Name after deserialization"); Assert.That( NHibernateUtil.IsPropertyInitialized(le2, nameof(LazyTextEntity.Text)), Is.False, "Lazy Text property should not be initialized on le2 after deserializing it"); Assert.That(le2.Text, Is.EqualTo("Text2"), "le2.Text after deserialization"); Assert.That(le2.IsProxy(), Is.False, "le2 should not be a lazy entity proxy after deserializing it"); var ilte2 = await(ds.LoadAsync <ILazyTextEntity>(_idInterfacedLazyTextEntity2)); Assert.That( NHibernateUtil.IsInitialized(ilte2), Is.True, "ilte2 should be initialized after deserialization"); Assert.That(ilte2.Name, Is.EqualTo("2"), "ilte2.Name after deserialization"); Assert.That( NHibernateUtil.IsPropertyInitialized(ilte2, nameof(ILazyTextEntity.Text)), Is.False, "Lazy Text property should not be initialized on ilte2 after deserializing it"); Assert.That(ilte2.Text, Is.EqualTo("Text2"), "ilte2.Text after deserialization"); Assert.That(ilte2.IsProxy(), Is.False, "ilte2 should not be a lazy entity proxy after deserializing it"); var le3 = await(ds.LoadAsync <LazyTextEntity>(_idLazyTextEntity3)); Assert.That( NHibernateUtil.IsPropertyInitialized(le3, nameof(LazyTextEntity.Text)), Is.True, "Lazy Text property should be initialized on le3 after deserializing it"); Assert.That(le3.Name, Is.EqualTo("3"), "le3.Name after deserialization"); Assert.That(le3.Text, Is.EqualTo("Text3"), "le3.Text after deserialization"); Assert.That(le3.IsProxy(), Is.True, "le3 should be a lazy entity proxy after deserializing it"); var ilte3 = await(ds.LoadAsync <ILazyTextEntity>(_idInterfacedLazyTextEntity3)); Assert.That( NHibernateUtil.IsPropertyInitialized(ilte3, nameof(ILazyTextEntity.Text)), Is.True, "Lazy Text property should be initialized on ilte3 after deserializing it"); Assert.That(ilte3.Name, Is.EqualTo("3"), "ilte3.Name after deserialization"); Assert.That(ilte3.Text, Is.EqualTo("Text3"), "ilte3.Text after deserialization"); Assert.That(ilte3.IsProxy(), Is.True, "ilte3 should be a lazy entity proxy after deserializing it"); var le4 = await(ds.LoadAsync <LazyTextEntity>(_idLazyTextEntity4)); Assert.That( NHibernateUtil.IsInitialized(le4), Is.False, "le4 should not be initialized after deserialization"); Assert.That( NHibernateUtil.IsPropertyInitialized(le4, nameof(LazyTextEntity.Text)), Is.False, "Lazy Text property should not be initialized on le4 after deserializing it"); Assert.That(le4.Text, Is.EqualTo("Text4"), "le4.Text after deserialization"); Assert.That(le4.Name, Is.EqualTo("4"), "le4.Name after deserialization"); Assert.That(le4.IsProxy(), Is.True, "le4 should be a lazy entity proxy after deserializing it"); var ilte4 = await(ds.LoadAsync <ILazyTextEntity>(_idInterfacedLazyTextEntity4)); Assert.That( NHibernateUtil.IsInitialized(ilte4), Is.False, "ilte4 should not be initialized after deserialization"); Assert.That( NHibernateUtil.IsPropertyInitialized(ilte4, nameof(ILazyTextEntity.Text)), Is.False, "Lazy Text property should not be initialized on ilte4 after deserializing it"); Assert.That(ilte4.Text, Is.EqualTo("Text4"), "ilte4.Text after deserialization"); Assert.That(ilte4.Name, Is.EqualTo("4"), "ilte4.Name after deserialization"); Assert.That(ilte4.IsProxy(), Is.True, "ilte4 should be a lazy entity proxy after deserializing it"); var le5 = await(ds.LoadAsync <LazyTextEntity>(_idLazyTextEntity5)); Assert.That( NHibernateUtil.IsInitialized(le5), Is.True, "le5 should be initialized after deserialization"); Assert.That(le5.Name, Is.EqualTo("5"), "le5.Name after deserialization"); Assert.That( NHibernateUtil.IsPropertyInitialized(le5, nameof(LazyTextEntity.Text)), Is.False, "Lazy Text property should not be initialized on le5 after deserializing it"); Assert.That(le5.Text, Is.EqualTo("Text5"), "le5.Text after deserialization"); Assert.That(le5.IsProxy(), Is.True, "le5 should be a lazy entity proxy after deserializing it"); var ilte5 = await(ds.LoadAsync <ILazyTextEntity>(_idInterfacedLazyTextEntity5)); Assert.That( NHibernateUtil.IsInitialized(ilte5), Is.True, "ilte5 should be initialized after deserialization"); Assert.That(ilte5.Name, Is.EqualTo("5"), "ilte5.Name after deserialization"); Assert.That( NHibernateUtil.IsPropertyInitialized(ilte5, nameof(ILazyTextEntity.Text)), Is.False, "Lazy Text property should not be initialized on ilte5 after deserializing it"); Assert.That(ilte5.Text, Is.EqualTo("Text5"), "ilte5.Text after deserialization"); Assert.That(ilte5.IsProxy(), Is.True, "ilte5 should be a lazy entity proxy after deserializing it"); await(t.CommitAsync()); } } finally { ds.Dispose(); } } }
public bool IsPropertyLoaded(object proxy, string propertyName) { return(NHibernateUtil.IsPropertyInitialized(proxy, propertyName)); }
private static Predicate <object> CreateShouldSerializeForLazyProperty(string propertyName) { return(entity => NHibernateUtil.IsPropertyInitialized(entity, propertyName)); }