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
andConta
- or what other approach I could use for that.