I have written a odata asp.net web api application in which i was returning a single object which was working fine. Now my requirement is to return multiple entities in GET request. While trying to do so i am getting the follwing error
[ArithmeticException]: Overflow or underflow in the arithmetic operation.
[HttpException]: An error occurred while communicating with the remote host. The error code is 0x80070216.
at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
at System.Web.Hosting.IIS7WorkerRequest.FlushCore(Boolean keepConnected, Int32 numBodyFragments, IntPtr[] bodyFragments, Int32[] bodyFragmentLengths, Int32[] bodyFragmentTypes)
at System.Web.Hosting.IIS7WorkerRequest.FlushCachedResponse(Boolean isFinal)
at System.Web.HttpResponse.UpdateNativeResponse(Boolean sendHeaders)
at System.Web.HttpRuntime.FinishRequestNotification(IIS7WorkerRequest wr, HttpContext context, RequestNotificationStatus& status)
-->
Controller
using Microsoft.AspNet.OData;
using adaptor.Models;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web;
using System;
using System.Collections.Generic;
using Microsoft.AspNet.OData.Routing;
using System.Web.Http.Results;
using System.Xml.Linq;
using System.Net.NetworkInformation;
using System.Reflection;
using Newtonsoft.Json.Linq;
using System.Collections;
namespace Webapplication1.Controllers
{
public class TableController : ApiController
{
TableContext db = new TableContext();
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
[ODataRoute("Table")]
[AcceptVerbs("GET")]
[HttpGet]
[EnableQuery(PageSize = 1000)]
public IHttpActionResult getAll()
{
try
{
var firstObject = new Table1();
var secondObject = new Table2();
var response = new MainModel();
{
response.Table1List = db.Tables1.ToList();
response.Table2List = db.Tables2.ToList();
};
return Ok(response);
}
catch (OverflowException)
{
return BadRequest("Arithmetic operation resulted in overflow.");
}
}
}
}
Model class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
namespace Webapplication1.Models
{
public class MainModel
{
public List<Table1> Table1List { get; set; }
public List<Table2> Table2List { get; set; }
}
}
TableContext class
public DbSet<Table1> Tables1 { get; set; }
public DbSet<Table2> Tables2 { get; set; }