I'm migrating a piece of software made in .NET Framework 4.7.2. I have an SQL Server database. For the creation of entities I added an ADO.net object using code first from database.
The entities were created, but when I execute the code it returns the following error
MEG_OFERTAS_MEG_OPERACIONES: : The types of all properties in the Dependent Role of a referential constraint must be the same as the corresponding property types in the Principal Role. The type of property 'DT_DIA_OPERACION' on entity 'MEG_OPERACIONES' does not match the type of property 'I_NRO_OFERTA' on entity 'MEG_OFERTAS' in the referential constraint 'MEG_OFERTAS_MEG_OPERACIONES'.
My entities are the following
public partial class MEG_OFERTAS : IEntity
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public MEG_OFERTAS()
{
MEG_OPERACIONES = new HashSet<MEG_OPERACIONES>();
MEG_OPERACIONES1 = new HashSet<MEG_OPERACIONES>();
}
[Key]
[Column(Order = 0, TypeName = "numeric")]
public decimal I_NRO_OFERTA { get; set; }
[Key]
[Column(Order = 1, TypeName = "datetime2")]
public DateTime DT_DIA_OPERACION { get; set; }
.
.
.
.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<MEG_OPERACIONES> MEG_OPERACIONES { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<MEG_OPERACIONES> MEG_OPERACIONES1 { get; set; }
}
and the other one is
public partial class MEG_OPERACIONES : IEntity
{
[Key]
[Column(Order = 0, TypeName = "numeric")]
public decimal I_NRO_OPERACION { get; set; }
[Key]
[Column(Order = 1, TypeName = "datetime2")]
public DateTime DT_DIA_OPERACION { get; set; }
[Column(TypeName = "numeric")]
public decimal I_NRO_OFERTA_COMPRA { get; set; }
[Column(TypeName = "numeric")]
public decimal I_NRO_OFERTA_VENTA { get; set; }
.
.
.
public virtual MEG_OFERTAS MEG_OFERTAS { get; set; }
public virtual MEG_OFERTAS MEG_OFERTAS1 { get; set; }
}
And in de dbcontext I have the next piece of code
modelBuilder.Entity<MEG_OFERTAS>()
.HasMany(e => e.MEG_OPERACIONES)
.WithRequired(e => e.MEG_OFERTAS)
.HasForeignKey(e => new { e.I_NRO_OFERTA_COMPRA, e.DT_DIA_OPERACION })
.WillCascadeOnDelete(false);
modelBuilder.Entity<MEG_OFERTAS>()
.HasMany(e => e.MEG_OPERACIONES1)
.WithRequired(e => e.MEG_OFERTAS1)
.HasForeignKey(e => new { e.I_NRO_OFERTA_VENTA, e.DT_DIA_OPERACION })
.WillCascadeOnDelete(false);
The ER Diagram for one of the relationships
Can anyone help me to solve my problem please?