【问题标题】:Convert object to int in Linq Where clause在 Linq Where 子句中将对象转换为 int
【发布时间】:2011-10-19 04:57:48
【问题描述】:

我正在尝试查询 DataColumn 的值等于数字的集合。问题是,我无法在 Linq 查询中将对象转换为 int。

错误在 where 子句中触发。有什么建议吗?

是否有我不知道的特殊语法?

var datos = _dttMasterViewTransaction.AsEnumerable().Where(r => r["JEID"] == FundsID).Select(r => new EntityJESummary()
{
    Test = r["test"]
}).ToList();

【问题讨论】:

  • _dttMasterViewTransaction是什么类型?

标签: c# linq int where


【解决方案1】:

特殊语法?选角算不算?

_dttMasterViewTransaction.AsEnumerable().Where(r => (int)r["JEID"] == FundsID)

【讨论】:

  • 这实际上是我尝试的第一件事,但我遇到了一个例外。现在它起作用了。去图吧!
  • 您可能也必须在 select 语句中这样做。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-17
相关资源
最近更新 更多