如何使用一个会话变量LINQ查询中的数据 [英] How to query data within a session variable using linq

查看:124
本文介绍了如何使用一个会话变量LINQ查询中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个asp.net Web窗体项目中有我,我从我的业务对象的数据填充会话变量。此对象包含这又必将GridView的Icollections。

within an asp.net webform project I have a session variable that I am populating with data from my business object. This object contains Icollections which in turn are bound to gridviews.

   myBase.GetAssocMInvolvedPeople(); //call to Business object
   if (myBase.AssocMInvolvedPeople != null)
    {
     Session["sessBase"] = myBase; //sync session with object results 
     gv_Names.DataSource = myBase.AssocMInvolvedPeople; //bind Icollection to grid
     gv_Names.DataBind();
     gv_Names.Visible = true;
    }

然后在我检索所选行的对象ID网格我行选择在

Then within my row selection on the grid I retrieve the object id of the selected row

GridDataItem selectedItem = (GridDataItem)gv_Names.SelectedItems[0]; 
SecondaryID = selectedItem["ObjectId"].Text;

我们的目标是把对象ID和查询会话变量(sessBase)来检索收集的剩余价值(即不可见的网格),并在一个形式/文本框格式UI显示它们。我想这样做的最好的办法是使用LINQ查询会话变量,但我在这里停留在如何去了解这个或访问嵌套集合(AssocMInvolvedPeople)。

The goal is to take the object Id and query the session variable (sessBase) to retrieve the remaining values (that were not visible in the gird) of the collection and display them in the UI in a form/textfield format. I would think the best approach for this would be to use Linq to query the session variable but I am stuck here on how to go about this or accessing the nested collection (AssocMInvolvedPeople) .

我会假设,在方法来设置此我会重置我的对象返回为会话变量:

I would assume that to set this up in the method I would reset my object back to the session variable as:

protected void GetAdditionalData()
{
 myBase = (BusinesObjectName)Session["sessBase"]; 

//here is where I am stuck how to query this object and select the records based upon the selected ID 
    ...
    }

我想AP preciate检索到这个数据上的最佳方法任何提示或建议

I would appreciate any tips or suggestions on the best approach to retrieving this data

感谢您,

推荐答案

如果您类型转换Session对象,并把它放在一个封闭,你应该能够使用它,或者在一个标准的LINQ对象中的任何集合属性查询,例如:

If you type-cast the Session object and put it in a closure, you should be able to use it or any collection property in the object in a standard LINQ query, i.e.:

var results =
    from MyClass i in (Session["sessBase"] as MyBusinessObject).MyCollection
    where secondaryID = i.ID
    select i

我意识到我做了关于你如何构造业务对象的一些武断决定,但不知道更多,我想这应该足以说明这个概念。

I realize I've made some arbitrary determinations about how you've structured the business object, but without knowing more, I think this should sufficiently demonstrate the concept.

这篇关于如何使用一个会话变量LINQ查询中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆