Error trying to insert data from a mixed table

0

I'm starting an MVC project and I'm having a problem that I can not fix.

[Table("InfoGeralEmpresa")]
public class InfoGeralEmpresa
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
    public InfoGeralEmpresa()
    {
        this.Cliente = new HashSet<Cliente>();
        this.Empresa = new HashSet<Empresa>();
        this.Fornecedor = new HashSet<Fornecedor>();
    }

    public int idInfoGeralEmpresa { get; set; }
    public Nullable<int> cnpj { get; set; }
    public string razaoSocial { get; set; }
    public string nomeFantasia { get; set; }
    public string inscEstadual { get; set; }
    public string email { get; set; }
    public int idEndereco { get; set; }

    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Cliente> Cliente { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Empresa> Empresa { get; set; }
    public virtual Endereco Endereco { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Fornecedor> Fornecedor { get; set; }
}

And a class that inherits InfoGeralEmpresa

[Table("Empresa")]
public class Empresa : InfoGeralEmpresa
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
    public Empresa()
    {
        this.Cargo = new HashSet<Cargo>();
        this.Cliente = new HashSet<Cliente>();
        this.Fornecedor = new HashSet<Fornecedor>();
        this.Funcionario = new HashSet<Funcionario>();
        this.OrdemServico = new HashSet<OrdemServico>();
        this.Setor = new HashSet<Setor>();
        this.StatusOS = new HashSet<StatusOS>();
    }

    public int idEmpresa { get; set; }
    //public int idInfoGeralEmpresa { get; set; }
    //[ForeignKey("idInfoGeralEmpresa")]

    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Cargo> Cargo { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Cliente> Cliente { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Fornecedor> Fornecedor { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Funcionario> Funcionario { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<OrdemServico> OrdemServico { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Setor> Setor { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<StatusOS> StatusOS { get; set; }
    public virtual InfoGeralEmpresa InfoGeralEmpresa { get; set; }
}

But when I do the insertion this way:

 db.InfoGeralEmpresa.Add(empresa);
 db.SaveChanges();

The following error appears

I do not know what to do, somebody help me.

    
asked by anonymous 08.06.2016 / 23:11

0 answers