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).
EF_4
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:EF_3
LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
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.
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
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.
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
https://onedrive.live.com/?cid=420CDD6A13807C9B&id=420CDD6A13807C9B%21116

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

Thanks,

Mike
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Fernando SotoRetiredCommented:
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.
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
It is possible there is something wrong with the database. I may try it with another database like Northwind to make sure.

Mike
0
Fernando SotoRetiredCommented:
Hi eghtebas;

I should have seen the issue earlier, the error message that it was giving was this, "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." When you do not select all fields from the table the Entity Framework query will return an Anonymous data type and NOT an Entity Dataset type. When the Include statement is used to include in the results other table object the Entity Framework query needs to return an EF data type and not an Anonymous type. To solve the issue you need to configure data source to return all the columns from the tblCustomers. Now after configuring the data source you are going to have more fields then you want to display. In the GridView Edit Columns and in the Listbox called "Selected fields" delete those fields you do not want in the GridView.
Final GridView Display
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Thank you very much.
0
Fernando SotoRetiredCommented:
Not a problem eghtebas, glad I was able to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.