Mapping 1 to 0, 0 to 1

0

I need to create a mapping between two existing entities, where both are independent.

Then.

I have one DepositoTransferencia entity and the other one is Conta . The idea is that at a given moment, the DepositoTransferencia entity records are only associated in Conta , but at first not. But the Conta records are not necessarily related to DepositoTransferencia .

What will happen at the system level is as follows: a user will register the deposits / transfers and another user will confirm this release, in which he confirms this release, the system has to make the deposit / transfer value available in the account of the user who has registered.

What I did:

[Table("DepositosTransferencias")]
public class DepositoTransferencia : BaseEntity
{
    [Key]
    public Guid DepositoTransferenciaId { get; set; }

    [Required]
    [DisplayName("Conta bancária")]
    public int ContaBancoId { get; set; }

    [ForeignKey(nameof(ContaBancoId))]
    public virtual ContaBanco ContaBanco { get; set; }

    [Required]
    [DisplayName("Número")]
    public string NumeroComprovante { get; set; }

    [DisplayName("Número no extrato")]
    public string NumeroExtrato { get; set; }

    [Required]
    [DisplayName("Data")]
    [DataType(DataType.Date)]
    [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
    public DateTime DataDocumento { get; set; }

    [DataType(DataType.Currency)]
    [Required]        
    public decimal Valor { get; set; }

    [DisplayName("Data de liberação")]
    public DateTime? DataLiberacao { get; set; }

    [DisplayName("Observação")]
    public string Observacao { get; set; }

    [Required]
    [DisplayName("Tipo")]
    public DepositoTransferenciaTipo Tipo { get; set; }

    [InverseProperty(nameof(DepositoTransferenciaSituacao.DepositoTransferencia))]
    public virtual ICollection<DepositoTransferenciaSituacao> DepositosTransferenciasSituacoes { get; set; }


}

[Table("Contas")]
public partial class Conta
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int ContaId { get; set; }
}

[Table("DepositosTransferenciasContas")]
public class DepositoTransferenciaConta
{
    [Key]
    [ForeignKey(nameof(DepositoTransferencia))]
    [Column(Order = 0)]
    [Index(IsUnique = true)]
    public Guid DepositoTransferenciaId { get; set; }

    [Key]
    [ForeignKey(nameof(Conta))]
    [Column(Order = 1)]
    [Index(IsUnique = true)]
    public int ContaId { get; set; }

    public virtual DepositoTransferencia DepositoTransferencia { get; set; }

    public virtual Conta Conta { get; set; }
}

My question is:

  • If what I did would be right.
  • How would I declare the inverse properties in DepositoTransferencia and Conta
  • or what other approach I could use for that.
asked by anonymous 10.08.2017 / 14:41

1 answer

1

You have created the DepositTransferAccount entity to intermediate the link between DepositBill and Account , but from what I understood from your rule: "a user will register the deposits / transfers and another user will confirm this release, in which he confirms this release, the system must make the deposit / transfer value available to the account of the user that has registered." , no I have seen the need for a many-to-many link between these two entities. I view the bank this way:

In this way, when registering the deposit the account will already be associated and with the field confirmed you can find out whether or not the deposit was accepted.

The confirmed field can be exchanged for a status field if you need other statuses for your deposit, other than confirmation.

    
18.08.2017 / 16:34