我正在尝试将此DataTable Select查询转换为Linq。目的是从列lookupValueField
中获取值private object[] GetValueFromLookup(MultipleKeyConditionBuilder filter, string lookupValueField, DataTable datatableLookup)
{
object[] result;
DataRow[] rows = datatableLookup.Select(filter.Condition);
result = new object[rows.Count()];
for (int i = 0; i < rows.Count(); i++)
{
result[i] = rows[0][lookupValueField];
}
return result;
}
这是我写的Linq查询。条件已在过滤器中定义。 filter包含以下类型的值'Project_id = 10'。如何在where子句中使用此过滤器。目前它给出了一个错误。 '不能隐含地将字符串转换为bool'
private object[] GetValueFromLookup(MultipleKeyConditionBuilder filter, string lookupValueField, DataTable datatableLookup)
{
object[] result;
EnumerableRowCollection<DataRow> rows;
//DataRow[] rows;
rows = from myRow in datatableLookup.AsEnumerable()
where filter.Condition
select myRow ;
result = new object[rows.Count()];
for (int i = 0; i < rows.Count(); i++)
{
result[i] = rows; // should give only lookupcolumn
//result[i] = rows[0][lookupValueField];
}
return result;
}
最后我想得到一个行数组而不是EnumerableRowCollection。我想要结果,因为它在上面的数组中。任何帮助都是有用的
答案 0 :(得分:0)
使用LINQ和Datatable.Select
方法的组合:
private object[] GetValueFromLookup(MultipleKeyConditionBuilder filter, string lookupValueField, DataTable datatableLookup)
{
IEnumerable<Object> query =
from rows in datatableLookup.Select(filter.Condition)
select rows.Field<Object>(lookupValueField);
return query.ToArray();
}