Complex type can have Entity Type property?

5

I have an Address class that is Complex Type . Can it have a state property that is an Entity Type ?

Class Code:

public class Endereco
{
   ...
   public string Logradouro { get; set; }
   public Estado Estado { get; set; }
}

public class Estado
{
   public int Id { get; set; }
   public string Nome { get; set; }
}

Class Mapping:

public class EnderecoConfiguracao: ComplexTypeConfiguration<Endereco>
{
   public EnderecoConfiguracao()
   {
       ...
       //fields
       Property(e => e.Logradouro).HasColumnName("Logradouro").HasMaxLength(200);
    }
}

public class EstadoConfiguracao: EntityTypeConfiguration<Estado>
{
    public EstadoConfiguracao()
    {            
        //Key
        HasKey(e => e.Id);

        //fields
        Property(e => e.Nome).HasColumnName("Nome").HasMaxLength(50).IsRequired();

        //table
        ToTable("estado");
    }
}

In my model, the Client has an Address, but when trying to map the State property of this address the following errors occurred:

1st Error: If I map Message State "Hba.HbaTools.Infraestrutura.EntityFramework.Estado: Name: Each type name in a schema must be unique. Type name 'Status' is already defined. "

asked by anonymous 06.01.2016 / 18:59

1 answer

3

Renan, now I understand your problem. Unfortunately it is not possible to reference a Entidades in Tipos Complexos .

So to maintain this structure, you will have to transform Endereco to Entidade , discard Endereco and move its properties to Cliente or remove Estado property from Endereco . >     

06.01.2016 / 21:29