0
I need to create a map between two existing entities, where both are independent.
So.
I have an entity DepositoTransferencia
and the other is Conta
. The idea is that at a given time, the entity records DepositoTransferencia
are associated only once in Conta
, but not at first.
But the records of Conta
not necessarily related to DepositoTransferencia
.
What will happen at the system level is the following: one user will register the deposits/transfers and another user will confirm this release, in which he confirms this release, the system has to provide the amount of deposit/transfer in the account of the user who 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 was right.
- How would I declare the reverse properties in
DepositoTransferencia
andConta
- or what other approach I could use to such an issue.
In reality what I want is a 1 to 1 ratio between Depositotransferencia and Account, why I created the link table, where in the columns
ContaId
andDepositoTransferenciaId
are defined as Unique. However, there may be data in Account that do not exist in Depositotransferencia, as well as data in Depositotransferencia that do not exist in Account. As you propose, I would have a 1-to-N relationship between Account and Depositotransference– Pablo Tondolo de Vargas
Whenever you make a deposit it will need to be associated with the account, right? There is a deposit that has no account ?
– Gustavo Gois Cardoso
Yes, it will only go to the account after confirmation, if it is not confirmed, it will not exist in the account.
– Pablo Tondolo de Vargas
Both solutions solve the problem. The difference is that in its solution the payment confirmation is done through another table, in mine, the confirmation is in the deposit entity itself. .
– Gustavo Gois Cardoso