question

robm-4957 avatar image
0 Votes"
robm-4957 asked DuaneArnold-0443 commented

Piecing together a entity framework application from 2014 , database issues.

Hi All!

I have an application that was built in 2014 using Entity Framework, the database as a whole was lost as the research group did not "pay its bills" to the service provider, I have been tasked with rebuilding it. I was able to push the the DataModel to the database server and recover a blank database , with a little massaging to get things in order.

I am now manually populating the data , I have run into some weird problems one of which is described here I will start with an image of the debug error.

86643-progress.gif


the details of the error are:

System.Web.HttpException
HResult=0x80004005
Message=Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.
Source=System.Web.Mvc
StackTrace:
at System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter)
at System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper htmlHelper, String actionName, Object routeValues)
at ASP._Page_Views_Survey_Progress_cshtml.Execute() in d:\code\SwatCORS\merrittr-swat-0bfb4e658cdd\SWAT_legacy\SWAT-Source Code\SWAT\SWAT\Views\Survey\Progress.cshtml:line 13
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
at System.Web.WebPages.StartPage.RunPage()
at System.Web.WebPages.StartPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)

Inner Exception 1:
InvalidOperationException: Sequence contains no elements




I see it is line 13 that is the issue , seems like there is no data for the PiChart is there a wat to see where the data the piechart is missing is?

sql-server-generaldotnet-csharpdotnet-entity-framework
progress.gif (203.1 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

robm-4957

I think you have missed tags you should be posting to, like dotnet-aspnet and dotnet-aspnet-mvc, IMHO.

0 Votes 0 ·

1 Answer

karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered

Seeing sequence contains no elements sounds like there is no data if reading without a where condition or there is a where condition which when executed had nothing to return in regards to the .Where or .FirstOrDefault etc. So if we used the query statement below if the category does not exists we get no elements/records back.

In both cases done properly one would create a unit test method to validate this.

If not familiar with unit test time to set a breakpoint back in the service and check to see the query results or in this case no results. Unit test to validate or invalidate this and other code to known if the code is correct or not.

DO NOT be looking at the view level until you ruled out backend code first.

Another option is to turn on logging and examine the SQL generated by EF or write an SQL statement which matches what you think your EF query is doing.

Lastly make sure you are looking at the right database server and table, see coders get this wrong many times.


 public static async Task<List<Product>> GetProductsWithProjection(int categoryIdentifier, bool discontinued)
 {
     var productList = new List<Product>();
    
     await Task.Run(async () =>
     {
    
         productList = await Context.Products
             .Include(product => product.Supplier)
             .Where(product => product.CategoryId == categoryIdentifier && 
                                         product.Discontinued == discontinued && 
                                         product.UnitsInStock >0)
             .Select(Product.Projection)
             .ToListAsync();
    
     });
 }


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.