迭代值 [英] Iterating values
本文介绍了迭代值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是linq的新手.我正在使用linq从数据库中填充一些类.
I'm new to linq. I'm using linq to fill some classes from the database.
我的所有对象都使用linq正确填充,除了一件小东西.在下面,您可以看到"SAR"飞行方向"(行15,16)的值应为升序和降序.但是我得到的是升序"的两个值对象.
All my objects are being filled correctly using my linq except for one small thing. Below you can see that for "SAR" "Flight Direction" (rows 15,16) I should have a value for Ascending and a value for Descending. But what I'm getting are two value objects for "Ascending".
为什么它没有遍历我的价值观? LINQ缺少什么?
using (NpgsqlDataReader reader = command.ExecuteReader())
{
if (reader.HasRows)
{
var groups = reader.Cast<System.Data.Common.DbDataRecord>()
.GroupBy(dr => new { ID = (int)dr["id"], AttID = (int)dr["AttId"] })
.GroupBy(g => g.Key.ID);
typeDataList = (
from typeGroup in groups
let typeRow = typeGroup.First().First()
select new TypeData()
{
ID = (int) typeRow["id"],
Type = (string) typeRow["type"],
Attributes =
(
from attGroup in typeGroup
let attRow = attGroup.First()
select new TypeDataAttribute()
{
ID = (int)attRow["AttId"],
Label = (string)attRow["label"],
PossibleValues =
(
from row in attGroup
where !DBNull.Value.Equals(attRow["AttValueId"])
select new TypeDataAttributeValue() { ID = (int)attRow["AttValueId"], Value = (string)attRow["value"] }
).ToArray()
}
).ToArray()
}
);
}
}
推荐答案
您要从attRow
中获取Value
,您应该从row
中获取它.
You are taking Value
from attRow
, you should take it from row
.
这篇关于迭代值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文