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 at
http://groups.google.com/group/nhcdevs?hl=en.