?
Solved

Help with Entity Framework, asp.net

Posted on 2014-11-28
8
Medium Priority
?
755 Views
Last Modified: 2014-11-28
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
0
Comment
Question by:Mike Eghtebas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40471167
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
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 40471170
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
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 40471175
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40471185
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
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 40471199
It is possible there is something wrong with the database. I may try it with another database like Northwind to make sure.

Mike
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 40471232
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
 
LVL 34

Author Closing Comment

by:Mike Eghtebas
ID: 40471243
Thank you very much.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40471246
Not a problem eghtebas, glad I was able to help.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question