I'm having the following problem, eh tried everything but I can not remove this error and list data to the referenced table. This is my Model Items:
namespace Project.Models
{
//[Bind(Exclude = "ID")]
public class Item
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
[Key]
//[ScaffoldColumn(false)]
[DisplayName("ID Producto")]
public int ProductoID { get; set; }
// FOREIGN KEY
[DisplayName("SubCategoria")]
public int SubCategoriaID { get; set; }
// FOREIGN KEY
[DisplayName("Proveedor")]
public int ProveedorID { get; set; }
[Required(AllowEmptyStrings = false,ErrorMessage = "El codigo es obligatorio")]
[DisplayFormat(ConvertEmptyStringToNull = false)]
[DisplayName("Codigo")]
public string Codigo { get; set; }
[Required(ErrorMessage = "El nombre obligatorio")]
[StringLength(160)]
[DisplayName("Nombre")]
public string Nombre { get; set; }
public virtual SubCategoria SubCategoria { get; set; }
public virtual List<PedidoItems> PedidoItems { get; set; }
public virtual Proveedor Proveedor { get; set; }
public List<Imagen> Imagenes { get; set; }
}}
The other is the model Order Items:..................................................................
namespace Project.Models
{
public class PedidoItems
{
public int PedidoItemsId { get; set; }
public int PedidoId { get; set; }
public int ProductoID { get; set; }
public int iCantidad {get;set;}
public decimal dPrecio {get;set;}
public decimal SubTotal { get; set; }
public virtual Item Item { get; set; }
public virtual Pedido Pedido { get; set; }
}}
And this is the part of the controller: ..................................................
public ActionResult MisPedidosDetalle([DataSourceRequest] DataSourceRequest request) {
var query = from p in db.PedidoItems //.Include("Items")
select new
{
p.PedidoId,
p.ProductoID,
p.iCantidad,
p.dPrecio,
p.SubTotal,
Item = p.Item
};
return Json(query.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
And the error is:
A circular reference was detected while serializing an object of type 'System.Data.Entity.DynamicProxies.PedidoItems_5E36688B06490D0B390FC180720173FC760260F84829E31D11D9F197ED76C978'.