EF mapping with generic classes

Asked

Viewed 30 times

0

I have a project that used Nhibernate with a generic/abstract class structure that was mapped without problems. the problem is that I was forced to migrate to Entity Framework and now I’m lost in how to do the mapping.

public abstract class CadastroMestre
{
    public virtual Int32 Identificador { get; set; }
    public virtual String Descricao { get; set; }
}

public abstract class MestreDetalhe : CadastroMestre
{
    public virtual CadastroMestre Mestre { get; set; }
    public virtual CadastroMestre Detalhe { get; set; }
}

public abstract class CadastroMestreLista : CadastroMestre
{
    public virtual IList<MestreDetalhe> Detalhes { get; set; }
}

public class TipoDocumento : CadastroMestre
{
}

public class TipoPessoa : CadastroMestreLista
{
}

public class RelacionamentoTipoPessoaTipoDocumento : MestreDetalhe
{
    public virtual Boolean Obrigatorio { get; set; }

    public RelacionamentoTipoPessoaTipoDocumento()
    {
        Mestre = new TipoPessoa();
        Detalhe = new TipoDocumento();
    }
}

I’m having trouble mapping these objects with their correct names. these are just one example, as there are several other objects using the same classes.

  • Do you want each class to represent a table in the database? or just the final implementation of each entity?

  • I need to map the classes Typopy, Typodocument and Relationshiptypessoatipodocumento. document type is quiet. the problem is to map Details (which is in Master Register) in the Type class, which is a list of Relationshiptypes.

  • how it mapped in Nhibernate: ;code <bag name="Details" Cascade="all-delete-Orphan" inverse="true"> <key column="RPD_MESTRE" /> <one-to-Many class="Framework.Model.Entity.Carties.Relationshipssoftypopping"/> </bag> code ;code <many-to-one name="Mestre" column="RPD_MESTRE" class="Framework.Modelo.Entidade.Cadastro.TipoPessoa" not-null="true" />&#xA; <many-to-one name="Detalhe" column="RPD_DETALHE" class="Framework.Modelo.Entidade.Cadastro.TipoDocumento" not-null="true" />code

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.