我需要从数据库中传递一些结果。我试图传递一个LinqDataSource配置的对象,而不是传递一个完整的数据集或一个构造的sql查询。通过会话传递LinqDataSource:在Dispose之后访问'DataContext'。
在源页上,我配置的LinqDataSource对象属性凡和WhereParameters使用通过在页面(搜索框,组合框等等)上显示的控制用户设置的值。我传递该对象以避免在接收者页面上重新配置LinqDataSource。
但是,即使它的工作我开发的系统上很好,在专用服务器上部署它后,我收到错误消息如下:
无法访问已释放的对象。
对象名称:'DataContext在Dispose。后访问'。
在这两个页面,源和接收器,在使用LinqDataSource对象被声明为:
<asp:LinqDataSource ID="myLinqDS" runat="server"
ContextTypeName="MyProject.MyDBNamedpace.MyDataContext"
TableName="TheTable"
OrderBy="field1, field2"
</asp:LinqDataSource>
要通过数据源对象周围我这样做:
SetLinqDataSourceWhereAndHisParameters(); //just set Where and WhereParameters
Guid guid = Guid.NewGuid();
Session[guid.ToString()] = myLinqDS;
ScriptManager.RegisterStartupScript(this.Page,
typeof(Page),
"Redirect",
String.Format(@"window.open(""{0}"");",
this.ResolveClientUrl("~/PageToDisplayTheData.aspx?guid=" +
System.Web.HttpUtility.UrlEncode(guid.ToString())
),
true);
,并检索,在PageToDisplayTheData.aspx的代码隐藏:
myLinqDS =
(LinqDataSource)Session[System.Web.HttpUtility.UrlDecode(Request.QueryString[guid])];
aDataList.DataSource = myLinqDS;
aDataList.DataBind();
结果集使用用户提供的数据进行过滤:搜索,组合框,单选按钮等。在上面的示例中,我在SetLinqDataSourceWhereAndHisParameters()上封装了该逻辑。 – Seiti 2009-01-19 16:33:02