Hi Pierre, yes, later I understood this mechanism. But I think this can be left as a suggestion of improvement, since there may be an hierarchy of attributes implicitly set in the constructor. Well, at least I think this hierarchy exists.
Thanks! On 23 dez 2010, 14:41, Pierre Henri Kuate <[email protected]> wrote: > Hi Henrique, > > The usual way to solve this limitation of .NET is to provide that order as the > first parameter of each attribute. So without changing NHMA, you can write: > > [Id(Name = "OperacaoId"), Generator(1, Class = "identity")] > > Note that I added a "1" before Class... > > HTH, > Pierre Henri. > > ________________________________ > From: Tensfeld <[email protected]> > To: NHibernate Contrib - Development Group <[email protected]> > Sent: Wed, December 22, 2010 5:46:39 PM > Subject: NH Mapping Attributes Bug (?) and Solution > > Hi, > I have the following code: > > _configuration.AddInputStream(HbmSerializer.Default.Serialize(typeof(Operacao))); > > _configuration.AddInputStream(HbmSerializer.Default.Serialize(typeof(Usuario))); > string[] script = > _configuration.GenerateSchemaCreationScript(new > NHibernate.Dialect.MsSql2005Dialect()); > > And classes begins like this: > [Class(Lazy = true)] > public class Operacao > { > [Id(Name = "OperacaoId"), Generator(Class = "identity")] > virtual public int OperacaoId { get; set; } > > [Class(Lazy = true)] > public class Usuario > { > [Id(Name = "UsuarioId"), Generator(Class = "identity")] > virtual public int UsuarioId { get; set; } > > The GenerateSchemaCreationScript generates: > create table Operacao (OperacaoId INT not null, Operador NVARCHAR(32) > null, Descricao NVARCHAR(32) null, primary key (OperacaoId)) > create table Usuario (UsuarioId INT IDENTITY NOT NULL, Login > NVARCHAR(32) null, Senha NVARCHAR(32) null, primary key (UsuarioId)) > > See that there's no IDENTITY in the first query. The reason is that > Visual Studio compiler is returning the atribute collection not > ordered. The line is in the HbmWriter.WriteClass() function: > object[] attributes = > type.GetCustomAttributes(typeof(ClassAttribute), false); > > The solution that I've found was, to modify the base constructor call > in GeneratorAttribute.cs, instead of always define order 0, it defines > order 1, so the Id attribute will sort before Generator attribute: > > GeneratorAttribute() : base(1) instead of GeneratorAttribute() : > base(0). > > Of course this solution should be applied to all attribute base > constructors so the correct priority should be defined, but I am not > even sure there isn't anything strange that I am not seeing in my > VS2008. > > Can someone tell me if this is right? > > -- > You received this message because you are subscribed to the Google Groups > "NHibernate Contrib - Development Group" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group > athttp://groups.google.com/group/nhcdevs?hl=en. -- You received this message because you are subscribed to the Google Groups "NHibernate Contrib - Development Group" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhcdevs?hl=en.
