/// <summary> /// Visits the field. /// </summary> /// <remarks> /// Infer column name and nullablity /// </remarks> /// <param name="model">The model.</param> public override void VisitField(FieldModel model) { if (model.FieldAtt.Column == null) { model.FieldAtt.Column = model.Field.Name; } // Append column prefix model.FieldAtt.Column = columnPrefix + model.FieldAtt.Column; Type fieldType = model.Field.FieldType; if (NHibernateNullablesSupport.IsNHibernateNullableType(fieldType) && (model.FieldAtt.ColumnType == null || model.FieldAtt.ColumnType.Length == 0)) { model.FieldAtt.NotNull = false; model.FieldAtt.ColumnType = NHibernateNullablesSupport.GetITypeTypeNameForNHibernateNullable(fieldType); } if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Nullable <>) && String.IsNullOrEmpty(model.FieldAtt.ColumnType)) { model.FieldAtt.NotNull = false; model.FieldAtt.ColumnType = ObtainNullableTypeNameForCLRNullable(fieldType); } JoinedTableModel joinedTable = ObtainJoinedTableIfPresent(model.Field, model.FieldAtt); if (joinedTable != null) { joinedTable.Fields.Add(model); } }
/// <summary> /// Visits the property. /// </summary> /// <remarks> /// Infer column name and whatever this propery can be null or not /// Also catch common mistake of try to use [Property] on an entity, instead of [BelongsTo] /// Ensure that joined properties have a joined table. /// </remarks> /// <param name="model">The model.</param> public override void VisitProperty(PropertyModel model) { if (model.PropertyAtt.Column == null) { model.PropertyAtt.Column = model.Property.Name; } // Append column prefix model.PropertyAtt.Column = columnPrefix + model.PropertyAtt.Column; Type propertyType = model.Property.PropertyType; if (NHibernateNullablesSupport.IsNHibernateNullableType(propertyType) && (model.PropertyAtt.ColumnType == null || model.PropertyAtt.ColumnType.Length == 0)) { model.PropertyAtt.NotNull = false; model.PropertyAtt.ColumnType = NHibernateNullablesSupport.GetITypeTypeNameForNHibernateNullable(propertyType); } if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable <>) && String.IsNullOrEmpty(model.PropertyAtt.ColumnType)) { model.PropertyAtt.NotNull = false; model.PropertyAtt.ColumnType = ObtainNullableTypeNameForCLRNullable(propertyType); } if (ActiveRecordModel.GetModel(propertyType) != null) { throw new ActiveRecordException(String.Format( "You can't use [Property] on {0}.{1} because {2} is an active record class, did you mean to use BelongTo?", model.Property.DeclaringType.Name, model.Property.Name, propertyType.FullName)); } JoinedTableModel joinedTable = ObtainJoinedTableIfPresent(model.Property, model.PropertyAtt); if (joinedTable != null) { joinedTable.Properties.Add(model); } }