如何一次单步浏览 IList 的一个字段?

发布于 2024-10-16 06:18:34 字数 898 浏览 6 评论 0原文

我正在使用动态 LINQ 库代码示例来动态返回一些数据。我返回的列数根据用户输入而变化。我将 IQueryable 枚举到 IList 中。

我需要做的是一次遍历 Ilist 一个字段。我可以通过迭代 IList 的行来一次获取一行,但我一生都无法从集合中提取一个字段。

例如,这里我返回两列(硬编码用于测试,但在产品中它将根据用户选择的字段而变化):

Dim Dynq = dc.dt _
                    .Where("RUN_ID = """ & runNumber & """ and Upper_Pressure > 95") _
                    .OrderBy("Upper_Pressure") _
                    .Select(" new (Run_ID,Process)")

        Dim something = DirectCast(Activator.CreateInstance(GetType(List(Of )).MakeGenericType(Dynq.ElementType), Dynq), IList)

现在,如果我知道列名,我可以从 Ilist 中提取一个字段,例如:

something.Run_ID.ToString

但我直到运行时才知道我正在使用的列,并将其动态插入到运行时设置的变量中是行不通的。

所以总而言之,我有一个看起来像这样的 Ilist

1  |  Auto
2  |  Auto
3  |  Manual
4  |  Manual

,我想要一种返回方式 1 然后返回 汽车 进而 2 等等...

我非常感谢那些比我更有学识的人在这方面的帮助。

I'm using the Dynamic LINQ library code sample to dynamically return some data. The number of columns I'm returning is variable depending on user input. I'm enumerating the IQueryable into an IList.

What I need to do is step through the Ilist one field at a time. I can get one row at a time by iterating through the IList's rows but I can't for the life of me pull one field out of the collection.

For example, here I'm returning two columns (hard coded for testing but in prod it will be variable depending on what fields the user chooses):

Dim Dynq = dc.dt _
                    .Where("RUN_ID = """ & runNumber & """ and Upper_Pressure > 95") _
                    .OrderBy("Upper_Pressure") _
                    .Select(" new (Run_ID,Process)")

        Dim something = DirectCast(Activator.CreateInstance(GetType(List(Of )).MakeGenericType(Dynq.ElementType), Dynq), IList)

Now I can pull a field out of the Ilist if I know the column name with something like:

something.Run_ID.ToString

but I wont know the columns I'm using until runtime and dynamically inserting it in a variable that's set at runtime doesn't work.

So in Summary I have a Ilist that looks something like this

1  |  Auto
2  |  Auto
3  |  Manual
4  |  Manual

and I'd like a way to return
1
and then return
Auto
and then
2
etc...

I would greatly appreciate the help of those more learned than I in this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗失的美好 2024-10-23 06:18:34

您的问题有点令人困惑,但我认为您想要展平您的返回集,以按列然后行的顺序返回特定列作为元素...

您可以使用的一种方法是 SelectMany 运算符。

例如(抱歉,在 C# 中,因为我的大脑正在转向单一轨道!):

// Find flattened list of some explicitly specified property values...
var flattened = something.SelectMany(e => new [] { e.Run_ID.ToString(), e.Process.ToString() });

不确定这是否是您所追求的,但这可能是朝着正确方向迈出的一步。

Your question is a little confusing, but I think you want to flatten your return set to return specific columns as elements in order by column then row...

One method, you could use is the SelectMany operator.

For example (sorry in C# as my brain is turning one-tracked!):

// Find flattened list of some explicitly specified property values...
var flattened = something.SelectMany(e => new [] { e.Run_ID.ToString(), e.Process.ToString() });

Not sure if that's what your after, but it could be a step in the right direction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文