I have a problem creating fields using FluentNhibernate and Postgres. User Class:
public class Usuario {
public virtual int idUsuario { get; set; }
public virtual string nome { get; set; }
[NotNullNotEmpty]
public virtual string login { get; set; }
[NotNullNotEmpty]
public virtual bool ativo { get; set; }
[NotNullNotEmpty]
public virtual string senha { get; set; }
}
UserMap:
public UsuarioMap() {
Table("usuario");
Id(x => x.idUsuario).GeneratedBy.Identity().Column("id_usuario");
Map(x => x.nome).Column("nome").Length(50);
Map(x => x.login).Column("login").Not.Nullable().Length(30);
Map(x => x.ativo).Column("ativo").Not.Nullable();
Map(x => x.senha).Column("senha").Not.Nullable().Length(50);
}
If the table does not exist, it normally creates all fields, with correct size and validation not null:
CREATE TABLE public.usuario
(
id_usuario integer NOT NULL DEFAULT nextval('usuario_id_usuario_seq'::regclass),
nome character varying(50),
login character varying(30) NOT NULL,
ativo boolean NOT NULL,
senha character varying(50) NOT NULL,
CONSTRAINT usuario_pkey PRIMARY KEY (id_usuario)
)
But if the table exists and adds a field in the map class, it just creates the field without the validations:
**Class Usuario**
[NotNullNotEmpty]
public virtual string teste { get; set; }
.
**Class UsuarioMap**
Map(x => x.teste).Column("teste").Length(60).Not.Nullable();
.
CREATE TABLE public.usuario
(
id_usuario integer NOT NULL DEFAULT nextval('usuario_id_usuario_seq'::regclass),
nome character varying(50),
login character varying(30) NOT NULL,
ativo boolean NOT NULL,
senha character varying(50) NOT NULL,
teste character varying(60),
CONSTRAINT usuario_pkey PRIMARY KEY (id_usuario)
)
If someone has already gone through this and can help me, thank you because I've been searching for two days and I could not solve it.