0
In the "LOG" class, I am trying to enter the column name, which is a FK, using Fluentnhibernate References. I have the following class structure:
public class Pessoa
{
public virtual int Id { get; set; }
public virtual string Nome { get; set; }
}
public class PessoaAcesso : Pessoa
{
public virtual string Login { get; set; }
public virtual string Senha { get; set; }
public virtual bool Administrador { get; set; }
public virtual bool AcessoLiberado { get; set; }
public virtual IList<Log> Logs { get; set; }
public PessoaAcesso()
{
Logs = new List<Log>();
}
}
public class Log
{
public virtual int Id { get; set; }
public virtual PessoaAcesso PessoaAcesso { get; set; }
public virtual DateTime DataHora { get; set; }
public virtual LogAcao Acao { get; set; }
public virtual string Descricao { get; set; }
}
And their mappings:
public class PessoaMap : ClassMap<Pessoa>
{
public PessoaMap()
{
Id(x => x.Id).GeneratedBy.Identity();
Map(x => x.Nome)
.Not.Nullable()
.Length(100);
}
}
public class PessoaAcessoMap : SubclassMap<PessoaAcesso>
{
public PessoaAcessoMap()
{
KeyColumn("Id_Pessoa");
Map(x => x.Login)
.Not.Nullable()
.Length(50);
Map(x => x.Senha)
.Not.Nullable()
.Length(100);
Map(x => x.Administrador)
.Not.Nullable();
Map(x => x.AcessoLiberado)
.Not.Nullable();
HasMany(x => x.Logs)
.Cascade.All();
}
}
public class LogMap : ClassMap<Log>
{
public LogMap()
{
Id(x => x.Id).GeneratedBy.Identity();
Map(x => x.DataHora)
.Not.Nullable();
Map(x => x.Acao)
.Not.Nullable()
.CustomType<int>();
Map(x => x.Descricao)
.Not.Nullable()
.Length(200);
References(x => x.PessoaAcesso)
.Column("Id_PessoaAcesso")
.Not.Nullable();
}
}
When generating the table in SQL Server, it creates the "Personal Idaccess" column correctly, but ALSO creates the "Personal Access_id" column allowing null.
I have tried to enter the column name this way, but you get the same unexpected result:
References(x => x.PessoaAcesso, "Id_PessoaAcesso")
I don’t understand why I’m creating an extra column. What can it be?
You can post the mapping of the People class?
– Fernando Leal
Added @Fernando
– felipearon
SubclassMap
does what, changes some mapping behavior? You can post your code as well?– Fernando Leal
I added the full structure @Fernando
– felipearon
SubclassMap
is equalPessoaMap
? What method isKeyColumn("Id_Pessoa");
?– Fernando Leal
I am using Subclassmap, because Personal Accessaccess is 1:1 to Person (inheritance). How this is working properly. The Problem is with Log.
– felipearon
@Fernando added in Personal Accessomap - Hasmany(x => x.Logs). Keycolumn("Personal Idaccess") and Logmap - References(x => x.Personal Accessaccess). Column("Personal id_access"), and now it worked as expected. I just didn’t understand why I need to indicate in both relations the name of Id. Create an answer with this solution, or edit the question?
– felipearon
If your problem has been solved, create an answer with your solution so that others can easily identify the solution to the problem. And it is also clearer the solution so that we can analyze your doubt.
– Fernando Leal