Solved

Help with Entity Framework, asp.net

Posted on 2014-11-28
8
676 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 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

16 Experts available now in Live!

Get 1:1 Help Now