asp.net mvc - EntityReference can have no more than one related object -
i have 2 identical controller actions , 2 identical views (one has different javscript file it). 1 view works fine, other gets hung on ef error:
a relationship multiplicity constraint violation occurred: entityreference can have no more 1 related object, query returned more 1 related object. non-recoverable error.
i understand error doesn't make sense in context, when 1 view works , 1 doesn't. here bit 2 views causing choke (it's nasty lets ignore now...):
<% var x = ((ienumerable<project.models.booth>)viewdata["booths"]).where(b => b.rownumber == && b.columnnumber == j && b.boothgroupid == item.id).firstordefault(); %> <%if ( x != null) { %> <td class="assigned" title="<%: x.boothnumber %> - <%: x.exhibitor.name %>" style="width:<%: item.width %>px; height:<%: item.height %>px;"></td> <%} else { %> <td style="width:<%: item.width %>px; height:<%: item.height %>px;"></td> <%} %>
this controller action details view causes exception:
public actionresult details(int id) { var results = g in db.boothgroups g.planid == id select g; viewdata["id"] = id; var plan = (from p in db.plans p.id == id select p).firstordefault(); viewdata["imagepath"] = "/plans/" + plan.name.tostring().replace(" ", "").tolower() + "/" + plan.imagefilename; var booths = b in db.booths b.planid == id select b; viewdata["booths"] = booths; return view(results); }
this controller action 1 works, there call populate drop down list viewdata, removing doesn't seem affect 1 view or other.
public actionresult editassignment(int id) { var results = g in db.boothgroups g.planid == id select g; viewdata["id"] = id; var plan = (from p in db.plans p.id == id select p).firstordefault(); viewdata["imagepath"] = "/plans/" + plan.name.tostring().replace(" ", "").tolower() + "/" + plan.imagefilename; var exhibitors = e in db.exhibitors e.meetingcode == plan.meetingcode orderby e.name select e; viewdata["exhibitors"] = new selectlist(exhibitors, "id", "name"); var booths = b in db.booths b.planid == id select b; viewdata["booths"] = booths; return view(results); }
i'm rather stumped this, insight appreciated.
the error doesn't seem indicate problem, think should enumerate queries first , see happens.
var results = (from g in db.boothgroups g.planid == id select g).tolist();
and
var booths = (from b in db.booths b.planid == id select b).tolist();
as is, passing objectquery
view , can cause problems view rendering since objectcontext
may not in state in when made query. check model objects , make sure not calling db within somewhere.
Comments
Post a Comment