Link to home
Start Free TrialLog in
Avatar of Mike Eghtebas
Mike EghtebasFlag for United States of America

asked on

Help with Entity Framework, asp.net

I am trying to duplicate the example discussed at: https://www.youtube.com/watch?v=Z7713GBhi4k  You-Tube example displays Location names (a one-side field) along with Employee data (many-side). Because I am using a different database, my sample uses:

 Customers names (a one-side field) along with Order data (many-side).
User generated image
Question: How can I display Customer orders in nested gridview controls similar to the sample shown below?

I have the entire solution in zip file (Entity_Utube.zip about 2.7MB with the database in it). But because this files contains files with .sln extention, EE doesn't allow to be uploaded. Gmail account does the same but hotmail accounts allow this attachement. I will be glad to email it to you if you eamil me at eghtebas<at>hotmail<dot>com using a non-gmail account with subject line EE Question. This might help to quickly spot the following error messages:
Server Error in '/' Application.

The result type of the query is neither an EntityType nor a CollectionType with an entity element type. An Include path can only be specified for a query with one of these result types.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The result type of the query is neither an EntityType nor a CollectionType with an entity element type. An Include path can only be specified for a query with one of these result types.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[InvalidOperationException: The result type of the query is neither an EntityType nor a CollectionType with an entity element type. An Include path can only be specified for a query with one of these result types.]
   System.Data.Objects.Internal.ObjectFullSpanRewriter..ctor(DbCommandTree tree, DbExpression toRewrite, Span span, AliasGenerator aliasGenerator) +8589308
   System.Data.Objects.Internal.ObjectSpanRewriter.TryRewrite(DbQueryCommandTree tree, Span span, MergeOption mergeOption, AliasGenerator aliasGenerator, DbExpression& newQuery, SpanIndex& spanInfo) +80
   System.Data.Objects.Internal.ObjectQueryExecutionPlan.Prepare(ObjectContext context, DbQueryCommandTree tree, Type elementType, MergeOption mergeOption, Span span, ReadOnlyCollection`1 compiledQueryParameters, AliasGenerator aliasGenerator) +66
   System.Data.Objects.EntitySqlQueryState.GetExecutionPlan(Nullable`1 forMergeOption) +414
   System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +131
   System.Data.Objects.ObjectQuery`1.GetIListSourceListInternal() +13
   System.Data.Objects.ObjectQuery.System.ComponentModel.IListSource.GetList() +10
   System.Web.UI.WebControls.EntityDataSourceView.ContinueSelectTyped(DataSourceSelectArguments arguments, EntityDataSourceQueryBuilder`1 queryBuilder, ObjectQuery`1 queryT, Boolean wasQueryModified) +295
   System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelectTyped(DataSourceSelectArguments arguments, Creator qbConstructor) +2189
   System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +513
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +138
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
   System.Web.UI.WebControls.GridView.DataBind() +4
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
   System.Web.UI.Control.EnsureChildControls() +83
   System.Web.UI.Control.PreRenderRecursiveInternal() +42
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34237

Open in new window

Also, here is the image from You-Tube example:User generated image
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

It would be better if you upload the file to a web site where any expert wishing to assist can download it. EE does not allow direct emailing files for questions. If you do not have a web site to do this you can use Microsoft OneDirve. If you do not have a OneDrive account you can get one for free. When you upload the file make sure you upload to a public folder so that it can be accessed by others. One the file has been uploaded please post the link to the download file here.
Avatar of Mike Eghtebas

ASKER

This is fantastic. I am sure Microsoft has been sending invites now and then to join. I need to get my act together and start using it. I will use the link you have provided to upload it. And also post a link here.
https://onedrive.live.com/?cid=420CDD6A13807C9B&id=420CDD6A13807C9B%21116

Hi Fernando, please let me know if you can retrieve the zip file.

Thanks,

Mike
Hi eghtebas;

I have retrieve your project folder and have been able to unzip it and I am getting the same error. I need to take care of some things so I will not be able to work on it right away but I will look at it before I go to bed tonight.
It is possible there is something wrong with the database. I may try it with another database like Northwind to make sure.

Mike
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much.
Not a problem eghtebas, glad I was able to help.