Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.Net WebForms模型绑定GridView使用实体框架5.0.0.0_Asp.net_Entity Framework_Webforms_Model Binding - Fatal编程技术网

ASP.Net WebForms模型绑定GridView使用实体框架5.0.0.0

ASP.Net WebForms模型绑定GridView使用实体框架5.0.0.0,asp.net,entity-framework,webforms,model-binding,Asp.net,Entity Framework,Webforms,Model Binding,im绑定List到我的GridView,其中T是由EntityFramework从我的数据库创建的对象。我所说的表中有一个外键,我想在GridView中显示它对应的文本值 <asp:TemplateField HeaderText="Foreign Key Type"> <ItemTemplate> <asp:Label ID="LabelID" Visible="true" runat="server"

im绑定
List
到我的
GridView
,其中
T
是由
EntityFramework
从我的数据库创建的对象。我所说的表中有一个外键,我想在GridView中显示它对应的文本值

 <asp:TemplateField HeaderText="Foreign Key Type">
          <ItemTemplate>
              <asp:Label ID="LabelID" Visible="true"  runat="server"
                         Text="<%# Item.<foreignKeyTable>.Text %>"  >
              </asp:Label>                                               
          </ItemTemplate>
 </asp:TemplateField>

当我这样做时,我会得到以下错误

无法完成该操作,因为DbContext已被释放


我如何才能通过这一关?很可能,您的查询代码会执行以下操作:

using (var ctx = new SomeContext())
{
   var data = ctx.Data.Where(..).ToList();
   return data;
}

您可能没有using,但无论如何,上下文都有它的Dispose()方法,任何卸载的导航属性都将始终失败,因为没有可附加的活动上下文。即使您可以在一个方法中使用上下文,也可能不会全局存储上下文,只要您没有通过调用该方法或使用using语句显式地处理上下文,您就可以了。

我使用的是
GenericRepo
get all函数,现在我在具体回购协议中覆盖了它,并使用
Include
急切地加载相关实体。。。tnx供您输入