/// <summary> /// Gets the property chain database information. /// </summary> /// <param name="entityType"> /// Type of the entity. /// </param> /// <param name="memberChain"> /// The member chain. /// </param> /// <returns> /// A <see cref="DbInfoDto"/> /// </returns> public DbInfoDto GetPropertyChainDatabaseInformation( Type entityType, IEnumerable<MemberInfo> memberChain ) { Check.IsNotNull ( entityType, "entityType is required." ); var dbInfo = new DbInfoDto (); var reversedMemberChainList = memberChain.ToList (); reversedMemberChainList.Reverse (); string propertyPath = null; foreach ( var memberInfo in reversedMemberChainList ) { if ( propertyPath == null ) { propertyPath = memberInfo.Name; } else { propertyPath = memberInfo.Name + "." + propertyPath; } var parentType = memberInfo.DeclaringType; if ( typeof( IAggregateRoot ).IsAssignableFrom ( parentType ) || typeof( IAggregateNode ).IsAssignableFrom ( parentType ) ) { dbInfo = GetPropertyDatabaseInformation ( parentType, propertyPath ); break; } if ( !( parentType.GetCustomAttributes ( typeof( ComponentAttribute ), false ).Count () > 0 ) ) { throw new ArgumentException ( "Member Chain for mapping contains an invalid member." ); } } return dbInfo; }
/// <summary> /// Gets the property database information. /// </summary> /// <param name="entityType"> /// Type of the entity. /// </param> /// <param name="propertyPath"> /// The property path. /// </param> /// <returns> /// A <see cref="DbInfoDto"/> /// </returns> public DbInfoDto GetPropertyDatabaseInformation( Type entityType, string propertyPath ) { Check.IsNotNull ( entityType, "entityType is required." ); Check.IsNotNullOrWhitespace ( propertyPath, "propertyPath cannot be empty or whitespace." ); var classMapping = _sessionFactory.GetClassMetadata ( entityType ); var persister = classMapping as AbstractEntityPersister; var dbInfo = new DbInfoDto (); if ( persister != null ) { dbInfo.Table = persister.TableName; dbInfo.Column = string.Join ( ",", persister.GetPropertyColumnNames ( propertyPath ) ); dbInfo.DataType = persister.GetPropertyType ( propertyPath ).Name; } return dbInfo; }