Search by Selected Meals Fails

Dec 21, 2011 at 8:08 PM

Whenever I select a meal or meals and return to the screen to run the search, I get an error on this line of code:

o.Meals.Select(g => g.Id).Contains(m)

The error is:

EntityCommandExecutionException was unhandled by user code

Immediately after that error is another error on this line:

var rows = this.RenderView("rows", src.OrderByDescending(u => u.Id).Skip((page - 1) * ps).Take(ps));
>>Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerWrapper
Here is the exception detail for the first error:
System.Data.EntityCommandExecutionException was unhandled by user code
  Message=An error occurred while executing the command definition. See the inner exception for details.
  Source=System.Data.Entity
  StackTrace:
       at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
       at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
       at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
       at System.Data.Objects.ObjectQuery`1.Execute(MergeOption mergeOption)
       at System.Data.Objects.DataClasses.EntityCollection`1.Load(List`1 collection, MergeOption mergeOption)
       at System.Data.Objects.DataClasses.EntityCollection`1.Load(MergeOption mergeOption)
       at System.Data.Objects.DataClasses.RelatedEnd.Load()
       at System.Data.Objects.DataClasses.RelatedEnd.DeferredLoad()
       at System.Data.Objects.Internal.LazyLoadBehavior.LoadProperty[TItem](TItem propertyValue, String relationshipName, String targetRoleName, Boolean mustBeNull, Object wrapperObject)
       at System.Data.Objects.Internal.LazyLoadBehavior.<>c__DisplayClass7`2.b__1(TProxy proxy, TItem item)
       at System.Data.Entity.DynamicProxies.Dinner_4F58AA6B62BBCA7DA5EC00A2D90BABBAA92C1580D9B48E6882694F74AD4C2F31.get_Meals()
       at Omu.ProDinner.WebUI.Controllers.DinnerController.<>c__DisplayClass8.<>c__DisplayClassa.b__4(Int32 m) in C:\Webs\SSSProjects\prodinner\WebUI\Controllers\DinnerController.cs:line 28
       at System.Linq.Enumerable.All[TSource](IEnumerable`1 source, Func`2 predicate)
       at Omu.ProDinner.WebUI.Controllers.DinnerController.<>c__DisplayClass8.b__3(Dinner o) in C:\Webs\SSSProjects\prodinner\WebUI\Controllers\DinnerController.cs:line 28
       at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
       at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
       at System.Linq.OrderedEnumerable`1.d__0.MoveNext()
       at System.Linq.Enumerable.d__4d`1.MoveNext()
       at System.Linq.Enumerable.d__3a`1.MoveNext()
       at ASP.views_dinner_rows_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\Webs\SSSProjects\prodinner\WebUI\Views\Dinner\rows.ascx:line 2
       at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
       at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
       at System.Web.UI.Control.Render(HtmlTextWriter writer)
       at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
       at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
       at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
       at System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer)
       at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: System.InvalidOperationException
       Message=There is already an open DataReader associated with this Command which must be closed first.
       Source=System.Data
       StackTrace:
            at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command)
            at System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command)
            at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
            at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
            at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
            at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
            at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
            at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
            at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
       InnerException: 
Anyone have any ideas?
Thanks!
Coordinator
Dec 22, 2011 at 8:54 AM

I guess it's some problem with the DB, try running the unit tests, see if they work,

also try testing this line:

o.Meals.Select(g => g.Id).Contains(m)