fluent conventions

Adding conventions to the fluennt nhibernate mapping is as simple as:

			Fluently.Configure()
				.Database(Configurator.Database)
				.Mappings(m => Configurator.UseMappings(m))

		public void UseMappings(MappingConfiguration mappings)
		{
			mappings.FluentMappings.Conventions.Add(new AnsiStringConvention());
			AddMappings(mappings);
		}

	///
 /// Dont use NVarchar for any strings /// 

	internal class AnsiStringConvention : IPropertyConvention
	{

		private static Type stringType = typeof(string);

		#region IConvention Members

		public void Apply(FluentNHibernate.Conventions.Instances.IPropertyInstance instance)
		{
			if (instance.Property.PropertyType == stringType)
			{
				instance.CustomType("AnsiString");
			}
		}

		#endregion
	}

Leave a Comment