Solved

Help with Entity Framework, asp.net

Posted on 2014-11-28
8
666 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
  • 4
  • 4
8 Comments
 
LVL 62

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 33

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 33

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
 
LVL 62

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 33

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 62

Accepted Solution

by:
Fernando Soto earned 500 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 33

Author Closing Comment

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

Expert Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now