Doubt on Entity Modeling

0

I have an entity called Requests that satisfies the following business:

  • A request is made by an Employee (Entity), then it is changed by another Employee and then confirmed by a third Employee.
  • In a request I am sending a Client (Entity) from one Bed (Entity) to another Bed (Entity). Here is the current mapping:

    using System;
    using SG.ProjetoTCC.Domain.Entities.Local;
    
    namespace SG.ProjetoTCC.Domain.Entities
    {
        public class Solicitacao
        {
            public Solicitacao()
            {
                SolicitacaoId = Guid.NewGuid();            
    
            }
            public Guid SolicitacaoId { get; set; }
            public DateTime DataSolicitacao { get; set; }
    
            public Guid FuncionarioSolicitanteId { get; set; }
            public virtual Funcionario FuncionarioSolicitante { get; set; }
    
            public TipoSolicitacao TipoSolicitacao { get; set; }
            public Guid ClienteId { get; set; }
            public virtual Cliente Cliente { get; set; }
    
            public Guid LeitoLocalId { get; set; }
            public virtual Leito LeitoLocal { get; set; }
    
            public Guid LeitoDestinoId { get; set; }
            public virtual Leito LeitoDestino { get; set; }
            public DateTime DataReserva { get; set; }
    
            public Guid FuncionarioReservaId { get; set; }
            public virtual Funcionario FuncionarioReserva { get; set; }
            public DateTime DataConclusao { get; set; }
    
            public Guid FuncionarioConclusaoId { get; set; }
            public virtual Funcionario FuncionarioConclusao { get; set; }
            public DateTime Tempo { get; set; }
    
        }
    }
    
    A Request does not have many (IEnumerable) Employees, it has 3 employees, which are: Official Requestor (who requested a bed), ReservationReservator (who reserved the bed) and OfficialConclusion (who placed the client in the destination Bed), and also 2 beds; LeitoLocal, and LeitoDestino.

  • Is my design correct? Should I use a Collection (Collection) and a Collection (Official)?
  • Sorry if it got too confusing, but I think you can understand it the way I explained.

    Thanks,

    Hugs.

        
    asked by anonymous 16.02.2015 / 00:15

    1 answer

    0

    @SamuelGomes, yes it is correct.

    These properties are what we call Propriedades de Navegação , they allow us to quickly access another Entity that is bound to it.

    For example, in the Entity Solicitacao we have a navigation property named FuncionarioSolicitante , this property allows us to quickly access the Officer who requested this Request. Since each Solicitacao can only have 1 Solicitante function then it does not have to be a list.

    Since all navigation should allow for flow on both sides, the Funcionario Entity must have a property called SolicitacoesSolicitante , which allows you to quickly access all the Solicitacao that it performed. Because an employee can perform N requests, this property must be a collection ( DbSet ).

    This does not at any time prevent Funcionario from being the Applicant and the Deliverer of the same Solicitacao , however we will have distant navigation properties because they are different browsing streams.

    Normally each FK in the Database will give rise to a Navigation property in the entities involved, as in the example below:

    Foreign Keys

    1:N FK_Funcionario_Solicitacao_Solicitante (1 Officer -> N Request) 1:N FK_Funcionario_Solicitacao_Reserva (1 Officer -> N Request) 1:N FK_Funcionario_Solicitacao_Conclusao (1 Officer -> N Request)

    Entity - Official

    public virtual DbSet<Solicitacao> SolicitacoesSolicitante { get; set; }
    public virtual DbSet<Solicitacao> SolicitacoesReserva { get; set; }
    public virtual DbSet<Solicitacao> SolicitacoesConclusao { get; set; }
    

    Entity - Request

    public virtual Funcionario FuncionarioSolicitante { get; set; }
    public virtual Funcionario FuncionarioReserva { get; set; }
    public virtual Funcionario FuncionarioConclusao { get; set; }
    
        
    16.02.2015 / 01:08