How to change the name of the References column by Fluent Nhibernate?

0

In the "LOG" class, I'm trying to indicate the column name, which is an FK, using FluentNHibernate's 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 column "PersonPassword" correctly, but ALSO creates the column "PersonApp_id" allowing null.

I have tried to indicate the name of the column in this way, but it has the same unexpected result:

References(x => x.PessoaAcesso, "Id_PessoaAcesso")

I'm not understanding why you're creating an extra column. What can it be?

    
asked by anonymous 28.07.2014 / 16:02

1 answer

1

I made the column name indication for both PersonaMap () and LogMap (). It worked.

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)
            .KeyColumn("Id_PessoaAcesso")
            .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();
    }
}
    
28.07.2014 / 18:34