Define virtual field name

1

I have the following code in my model SubGrupo :

namespace Aplicacao.Core.Dominio
{
    public class SubGrupo
    {
        [Key]
        public int Codigo { get; set; }

        [Required(ErrorMessage = "Campo Obrigatório.")]
        public string Descricao { get; set; }

        public virtual TipoFormulario TipoFormulario { get; set; }
    }
}

Model TipoFormulario

namespace Aplicacao.Core.Dominio
{
    public class TipoFormulario
    {
        [Key]
        public int Codigo { get; set; }

        [Required(ErrorMessage = "Campo Obrigatório.")]
        public string Descricao { get; set; }
    }
}

In this case, the Key of the TipoFormulario model is Codigo . So in the database is generated TipoFormulario_Codigo

How can I set the name to be generated? I would like to name the column for TipoFormulario

    
asked by anonymous 10.09.2015 / 22:10

1 answer

2

So:

namespace Aplicacao.Core.Dominio
{
    public class SubGrupo
    {
        [Key]
        public int Codigo { get; set; }
        [Column("TipoFormulario")]
        [ForeignKey("TipoFormulario")]
        public int TipoFormularioId { get; set; }

        [Required(ErrorMessage = "Campo Obrigatório.")]
        public string Descricao { get; set; }

        public virtual TipoFormulario TipoFormulario { get; set; }
    }
}
    
10.09.2015 / 22:28