ASP.Net Web API showing correctly in VS but giving HTTP500 -
after lot of yesterday, came against known error in asp.net4 beta - upgraded vs2012 rc express (4.5), , i'm getting internal server error, , can't see why. i'm creating web api:
model
using system; using system.collections.generic; using system.linq; using system.web; using system.componentmodel.dataannotations; using system.data.entity.modelconfiguration.conventions; using system.data.entity; using system.componentmodel.dataannotations.schema; namespace mvcapplication6.models { public class tblcustomerbooking { [key()] public int customer_id { get; set; } public string customer_name { get; set; } public string customer_email { get; set; } public virtual icollection<tblrental> tblrentals { get; set; } } public class tblrental { [key()] public int rental_id { get; set; } public int room_id { get; set; } public datetime check_in { get; set; } public datetime check_out { get; set; } public decimal room_cost { get; set; } public int customer_id { get; set; } [foreignkey("customer_id")] public virtual tblcustomerbooking tblcustomerbooking { get; set; } } } i used add controller wizard, selected "template: api controller read/write actoins, using entity framework", chose tblcustomerbooking model class, , clicked , is:
using system.data.entity; namespace mvcapplication6.models { public class bookingscontext : dbcontext { public bookingscontext() : base("name=bookingscontext") { } public dbset<tblcustomerbooking> tblcustomerbookings { get; set; } } } my controller (bookingscontroller.cs) automatically generated visual studio 2012 express is:
using system; using system.collections.generic; using system.data; using system.data.entity.infrastructure; using system.linq; using system.net; using system.net.http; using system.web; using system.web.http; using mvcapplication6.models; namespace mvcapplication6.controllers { public class bookingscontroller : apicontroller { private bookingscontext db = new bookingscontext(); // api/bookings public ienumerable<tblcustomerbooking> gettblcustomerbookings() { return db.tblcustomerbookings.asenumerable(); } } } i added breakpoint @ "return db....." above, , checked watch part in vs - shows object, customer, , associated rentals:

however if allow script continue, http500 error (as shown in fiddler below): 
is there more code can add controller allow me see why erroring? or can see may wrong? vs appears retrieve ok, shown in first screenshot, doesn't seem able send out.
thanks or pointers,
mark
update
hi - asking of api? not possible (out of box) return objects 1 many relationships? can produce single object list?
thanks, mark
are doing:
db.tblcustomerbookings.include("tblrentals").select(i => new { i.something //etc }); also, mediatypeformatter using, xml or json? error 500 means formatter choking.
switch json.net formatter (in web api rc easiest way globalconfiguration.configuration.formatters.removeat(1) - removes xml formatter) , see if helps or @ least gives more meaningful error (or request method content type json).
Comments
Post a Comment