本文介绍了如何使用Entity Framework处理一对多关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有 4个表(预订,航班,席位,付款)我想在一个asp.net页面中使用 grid-view 和实体框架数据源。 我试试,但不正在工作。 示例: i已向asp添加2个实体数据源。 预订表的网页一,航班表 ai的网页输入以下代码:I had 4 tables (Booking,Flights,Seats,Payments) i want to link it together in one asp.net page using grid-view and entity-framework data source.I'm try it but its NOT working.Example:i had add 2 entity data source to asp.net page one for booking table and one for flights table a i had put the following code:<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="EntityDataSource1"> </asp:GridView> <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=ARS_DBEntities2" DefaultContainerName="ARS_DBEntities2" EnableFlattening="False" EntitySetName="Bookings" Include="" Select="it.[BookId], it.[NName], it.[BookDate], it.[Flights].[Price]" Where="it.[Booking].[FlightId] = it.[Flights].[FlightId] "> </asp:EntityDataSource> <asp:EntityDataSource ID="EntityDataSource2" runat="server" ConnectionString="name=ARS_DBEntities2" DefaultContainerName="ARS_DBEntities2" EnableFlattening="False" EntitySetName="Flights" Select="it.[FlightId], it.[DepartureTime], it.[DepartureCity], it.[ArrivalTime], it.[ArrivalCity], it.[Price]"> </asp:EntityDataSource> 我有这个错误:I've got this ERROR:Server Error in '/' Application.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:[EntitySqlException: 'Booking' is not a member of type 'ARS_DBModel.Booking' in the currently loaded schemas. Near escaped identifier, line 8, column 4.] System.Data.Common.EntitySql.SemanticResolver.ResolvePropertyAccess(DbExpression valueExpr, String name, ErrorContext errCtx) +8065736 System.Data.Common.EntitySql.SemanticAnalyzer.ConvertDotExpr(Node expr, SemanticResolver sr) +173 System.Data.Common.EntitySql.SemanticAnalyzer.Convert(Node astExpr, SemanticResolver sr) +72 System.Data.Common.EntitySql.SemanticAnalyzer.ConvertDotExpr(Node expr, SemanticResolver sr) +189 System.Data.Common.EntitySql.SemanticAnalyzer.Convert(Node astExpr, SemanticResolver sr) +72 System.Data.Common.EntitySql.SemanticAnalyzer.ConvertValueExpressionAllowUntypedNulls(Node astExpr, SemanticResolver sr) +21 System.Data.Common.EntitySql.SemanticAnalyzer.ConvertValueExpressionsWithUntypedNulls(Node leftAst, Node rightAst, ErrorContext errCtx, Func`1 formatMessage, SemanticResolver sr) +26 System.Data.Common.EntitySql.SemanticAnalyzer.ConvertEqualCompArgs(BuiltInExpr astBuiltInExpr, SemanticResolver sr) +96 System.Data.Common.EntitySql.SemanticAnalyzer.<CreateBuiltInExprConverter>b__83(BuiltInExpr bltInExpr, SemanticResolver sr) +11 System.Data.Common.EntitySql.SemanticAnalyzer.ConvertBuiltIn(Node astExpr, SemanticResolver sr) +107 System.Data.Common.EntitySql.SemanticAnalyzer.Convert(Node astExpr, SemanticResolver sr) +72 System.Data.Common.EntitySql.SemanticAnalyzer.ConvertValueExpressionAllowUntypedNulls(Node astExpr, SemanticResolver sr) +21 System.Data.Common.EntitySql.SemanticAnalyzer.ConvertValueExpression(Node astExpr, SemanticResolver sr) +12 System.Data.Common.EntitySql.SemanticAnalyzer.ProcessWhereHavingClausePredicate(DbExpressionBinding source, Node predicate, ErrorContext errCtx, String bindingNameTemplate, SemanticResolver sr) +44 System.Data.Common.EntitySql.SemanticAnalyzer.ConvertQueryExpr(Node expr, SemanticResolver sr) +147 System.Data.Common.EntitySql.SemanticAnalyzer.Convert(Node astExpr, SemanticResolver sr) +72 System.Data.Common.EntitySql.SemanticAnalyzer.ConvertValueExpressionAllowUntypedNulls(Node astExpr, SemanticResolver sr) +21 System.Data.Common.EntitySql.SemanticAnalyzer.ConvertParenExpr(Node astExpr, SemanticResolver sr) +42 System.Data.Common.EntitySql.SemanticAnalyzer.Convert(Node astExpr, SemanticResolver sr) +72 System.Data.Common.EntitySql.SemanticAnalyzer.ConvertValueExpressionAllowUntypedNulls(Node astExpr, SemanticResolver sr) +21 System.Data.Common.EntitySql.SemanticAnalyzer.ConvertValueExpression(Node astExpr, SemanticResolver sr) +12 System.Data.Common.EntitySql.SemanticAnalyzer.ProcessAliasedFromClauseItem(AliasedExpr aliasedExpr, SemanticResolver sr, List`1& scopeEntries) +26 System.Data.Common.EntitySql.SemanticAnalyzer.ProcessFromClauseItem(FromClauseItem fromClauseItem, SemanticResolver sr, List`1& scopeEntries) +61 System.Data.Common.EntitySql.SemanticAnalyzer.ProcessFromClause(FromClause fromClause, SemanticResolver sr) +133 System.Data.Common.EntitySql.SemanticAnalyzer.ConvertQueryExpr(Node expr, SemanticResolver sr) +117 System.Data.Common.EntitySql.SemanticAnalyzer.Convert(Node astExpr, SemanticResolver sr) +72 System.Data.Common.EntitySql.SemanticAnalyzer.ConvertValueExpressionAllowUntypedNulls(Node astExpr, SemanticResolver sr) +21 System.Data.Common.EntitySql.SemanticAnalyzer.ConvertQueryStatementToDbExpression(Statement astStatement, SemanticResolver sr, List`1& functionDefs) +61 System.Data.Common.EntitySql.SemanticAnalyzer.AnalyzeQueryCommand(Node astExpr) +50 System.Data.Common.EntitySql.CqlQuery.<AnalyzeQueryExpressionSemantics>b__8(SemanticAnalyzer analyzer, Node astExpr) +6 System.Data.Common.EntitySql.CqlQuery.AnalyzeSemanticsCommon(Node astExpr, Perspective perspective, ParserOptions parserOptions, IEnumerable`1 parameters, IEnumerable`1 variables, Func`3 analysisFunction) +172 System.Data.Common.EntitySql.CqlQuery.AnalyzeQueryExpressionSemantics(Node astQueryCommand, Perspective perspective, ParserOptions parserOptions, IEnumerable`1 parameters, IEnumerable`1 variables) +160 System.Data.Common.EntitySql.<>c__DisplayClass4.<CompileQueryCommandLambda>b__3(Node astCommand, ParserOptions validatedParserOptions) +22 System.Data.Common.EntitySql.CqlQuery.CompileCommon(String commandText, Perspective perspective, ParserOptions parserOptions, Func`3 compilationFunction) +98 System.Data.Common.EntitySql.CqlQuery.CompileQueryCommandLambda(String queryCommandText, Perspective perspective, ParserOptions parserOptions, IEnumerable`1 parameters, IEnumerable`1 variables) +100 System.Data.Objects.EntitySqlQueryState.Parse() +8610091 System.Data.Objects.EntitySqlQueryState.GetResultType() +4 System.Data.Objects.ObjectQuery.GetResultType() +58 System.Web.UI.WebControls.EntityDataSourceQueryBuilder`1.BuildBasicQuery(ObjectContext context, Boolean computeCount) +108 System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelectTyped(DataSourceSelectArguments arguments, Creator qbConstructor) +355 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() +168 System.Web.UI.Control.PreRenderRecursiveInternal() +168 System.Web.UI.Control.PreRenderRecursiveInternal() +168 System.Web.UI.Control.PreRenderRecursiveInternal() +168 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974 表格: https://www.dropbox.com/s /d7513srspj1zvt0/Capture.JPG [ ^ ] 谢谢the tables:https://www.dropbox.com/s/d7513srspj1zvt0/Capture.JPG[^]Thanks推荐答案 这篇关于如何使用Entity Framework处理一对多关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 02:58