I´m trying to make an insert in a m to m relation. (create a PayOrder (orden de pago) and a ticket (DocumentoProveedor)
How do i must set the relation in each class?
[Table("DocumentosProveedor")]
public class DocumentoProveedor
{
[Key]
public int DocumentoProveedorId { get; set; }
public TipoDocumento TipoDocumento { get; set; }
public int TipoDocumentoID { get; set; }
[RegularExpression(@"^(\d){3}$",ErrorMessage="El formato para la sucursal es de tres dígitos enteros: 001")]
public string Sucursal { get; set; }
[RegularExpression(@"^(\d){8}$", ErrorMessage = "El formato para el número de documento es de 8 dígitos enteros 00000001")]
public string NroDocumento { get; set; }
[Required]
public double Importe { get; set; }
[Display(Name="Importe IVA")]
[Required]
public double IVA { get; set; }
[DisplayFormat(DataFormatString = "{0:dd/MM/yy}",ApplyFormatInEditMode = true)]
[Required]
public DateTime Fecha { get; set; }
[DisplayFormat(DataFormatString = "{0:dd/MM/yy}",ApplyFormatInEditMode = true)]
public DateTime Vencimiento { get; set; }
public int ProveedorID { get; set; }
public Proveedor Proveedor { get; set; }
public int EstadoDocumentoProveedorID { get; set; }
public EstadoDocumentoProveedor Estado { get; set; }
[NotMapped]
public double Total {
get
{
return Importe + IVA;
}
}
[NotMapped]
public List<InformeRecepcion> InformesRecepcion { get; set; }
}
public class OrdenPago
{
[Key]
public int OrdenPagoID { get; set; }
public DateTime Fecha { get; set; }
public Proveedor Proveedor { get; set; }
public int ProveedorID{ get; set; }
public List<DocumentoProveedor>DocumentosPagados { get; set; }
}
when i search the documentoProveedor to add it to the ordenPago.DocumentosPagados list i get an error (Invalid column name 'OrdenPago_OrdenPagoID'), because expects to find the ordenPagoID in the documentoProveedorID, been that this id is at the
relation table.
sepilrat
Member
119 Points
87 Posts
Problems by insert m to m relation
Feb 16, 2012 06:19 PM|LINK
Hi.
I´m trying to make an insert in a m to m relation. (create a PayOrder (orden de pago) and a ticket (DocumentoProveedor)
How do i must set the relation in each class?
[Table("DocumentosProveedor")] public class DocumentoProveedor { [Key] public int DocumentoProveedorId { get; set; } public TipoDocumento TipoDocumento { get; set; } public int TipoDocumentoID { get; set; } [RegularExpression(@"^(\d){3}$",ErrorMessage="El formato para la sucursal es de tres dígitos enteros: 001")] public string Sucursal { get; set; } [RegularExpression(@"^(\d){8}$", ErrorMessage = "El formato para el número de documento es de 8 dígitos enteros 00000001")] public string NroDocumento { get; set; } [Required] public double Importe { get; set; } [Display(Name="Importe IVA")] [Required] public double IVA { get; set; } [DisplayFormat(DataFormatString = "{0:dd/MM/yy}",ApplyFormatInEditMode = true)] [Required] public DateTime Fecha { get; set; } [DisplayFormat(DataFormatString = "{0:dd/MM/yy}",ApplyFormatInEditMode = true)] public DateTime Vencimiento { get; set; } public int ProveedorID { get; set; } public Proveedor Proveedor { get; set; } public int EstadoDocumentoProveedorID { get; set; } public EstadoDocumentoProveedor Estado { get; set; } [NotMapped] public double Total { get { return Importe + IVA; } } [NotMapped] public List<InformeRecepcion> InformesRecepcion { get; set; } }public class OrdenPago { [Key] public int OrdenPagoID { get; set; } public DateTime Fecha { get; set; } public Proveedor Proveedor { get; set; } public int ProveedorID{ get; set; } public List<DocumentoProveedor>DocumentosPagados { get; set; } }when i search the documentoProveedor to add it to the ordenPago.DocumentosPagados list i get an error (Invalid column name 'OrdenPago_OrdenPagoID'), because expects to find the ordenPagoID in the documentoProveedorID, been that this id is at the relation table.
Thanks in advance
r
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Problems by insert m to m relation
Feb 18, 2012 05:36 AM|LINK
Hello:)
I think it seems you are now using EntityFramework (Code-First)and you've met with the kind of problem……
So plz try to change this statement I've referred above to this following by adding the key word of "virtual":
public virtual IList<DocumentoProveedor>DocumentosPagados { get; set; }
And in your DocumentProveedor class,you should also have another class refer like:
public virtual OrdenPago OrdenPago{get;set;}