Doubt about Entity Modeling

Asked

Viewed 101 times

0

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

  1. A request is made by an Employee(Entity), then it is changed by another Employee and then confirmed by a third Employee.
  2. In a request I am sending a Client(Entity) from one Bed(Entity) to another Bed(Entity). Below 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 Solicitation does not have many (Ienumerable) Employees, it has 3 employees, which are: Functionary (who requested a bed), Functionary(who reserved the bed) and Functionconclusion(who placed the client in the destination Bed), and also 2 Beds; Lectern, and Leitodestino.

  3. Is my design correct? I should use a Collection(Bed) and a Collection(Employee)?

I’m sorry if you got too confused, but I think you can understand the way I explained it.

Thank you,

Hugs.

1 answer

0


@Samuelgomes, is correct yes.

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

For example, In the Entity Solicitacao we have a call navigation property FuncionarioSolicitante, this property allows us to quickly access the Employee who requested this Request. Like each Solicitacao may have only 1 Official Solicitante then it doesn’t need to be a list.

As all navigation should allow the flow of both sides, the Entity Funcionariomust have a property called SolicitacoesSolicitante, that allows you to quickly access all Solicitacao that he held. As an employee can perform N requests, this property must be a collection (DbSet).

This at no time prevents the Funcionario cannot be the Requester and the Deliverer of the same Solicitacao, but we will have distinct navigation properties, as they are distinct navigation flows.

Usually 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 Staff -> N Request) 1:N FK_Funcionario_Solicitacao_Reserva (1 Staff -> N Request) 1:N FK_Funcionario_Solicitacao_Conclusao (1 Staff -> N Request)

Entity - Employee

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; }
  • Yes, I have 3 Fks. I didn’t understand your modeling Requestrequester, Requestreservation and Requestconclusionconclusion. Because in A Request I have 3 fields of the Employee type.

  • I’ve added some additional information, maybe it’ll help you understand better.

  • These properties SolicitacoesSolicitante, etc... belong to the entity Funcionario and not the Solicitante

  • Now I understand your reasoning. You are distinguishing Employee from: Requester = That Employee who Only Requests, Booking = That Who Only Reserves and Completion = That Who Completed the Request. However 1 Employee will make a request in the system, then another employee, or the same, will make the reservation of the bed, when the reserved bed is occupied, another employee or the same will make the Completion of the request. That is, in 1 request I will have to inform 3 employees. If that was your reasoning forgive me for not understanding.

  • At no time is there this limitation, I will rewrite the response to try to be clearer.

Browser other questions tagged

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