using System.ComponentModel.DataAnnotations; using FluentNHibernate.Conventions; using FluentNHibernate.Conventions.Instances;
namespace YourApp.Infrastructure.Conventions { public class ColumnNullConvention : IPropertyConvention { public void Apply(IPropertyInstance instance) { if (instance.Property.MemberInfo.IsDefined(typeof(RequiredAttribute), false)) instance.Not.Nullable(); } } } ---- using System.ComponentModel.DataAnnotations; using FluentNHibernate.Conventions; using FluentNHibernate.Conventions.Instances; namespace YourApp.Infrastructure.Conventions { public class ColumnLengthConvention : AttributePropertyConvention<StringLengthAttribute> { protected override void Apply(StringLengthAttribute attribute, IPropertyInstance instance) { // override the default column length if (attribute.MaximumLength != default(int)) instance.Length(attribute.MaximumLength); } } } ---------------- Make sure when you generate your mappings, you're actually adding all your conventions, something like mappings.Conventions.Setup(GetConventions()); private static Action<IConventionFinder> GetConventions() { return c => { c.AddFromAssemblyOf<ColumnNullConvention>(); }; } On Tue, May 21, 2013 at 9:46 AM, Riderman Sousa <riderma...@bindsolution.com > wrote: > Using DataAnnotations, I set my string properties with the length using > StringLength > attribute > > [StringLength(10)] > public virtual string Identificacao { get; set; } > > For this convection is applied to my database, I created a > StringLengthConventions see: http://chopapp.com/#jlu7vz5v > > Now I need to configure the properties as NotNull then follow the same > steps: > > 1. I added the attribute [Required] on properties. > 2. Create a RequiredConvention attribute, see: > http://chopapp.com/#4milknwk > > *Error* > > As you may have noticed, the conventions retrieve only the first > attribute. What generates an error in the generated schema. > The schema will follow the convention only the first attribute! > > *Question* > > The first step to fix the error is to create a test that fails. The > question is, how to create a test for conventions? > > Thanks, > > Riderman de Sousa Barbosa <http://about.me/ridermansb> > > Web Developer | MCPD Certify > > Skype.: 4042-6002 | Cel.: (31) 8681-1986 > bindsolution.com > > Microsoft Parner Network > > -- > You received this message because you are subscribed to the Google Groups > "Fluent NHibernate" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to fluent-nhibernate+unsubscr...@googlegroups.com. > To post to this group, send email to fluent-nhibernate@googlegroups.com. > Visit this group at > http://groups.google.com/group/fluent-nhibernate?hl=en-US. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To unsubscribe from this group and stop receiving emails from it, send an email to fluent-nhibernate+unsubscr...@googlegroups.com. To post to this group, send email to fluent-nhibernate@googlegroups.com. Visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.