`
61party
  • 浏览: 1051214 次
  • 性别: Icon_minigender_2
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

LINQ To DataSet:联合查询

阅读更多

输出

Anthony's Class is: null

这是为什么呢?因为这里发生的了装箱操作,

This is because of the boxing of the Id field when it is retrieved using the

DataRow indexer

在用DataRow索引器对Id字段进行检索的时候,该字段发生了装箱操作

导致join没有成功 "where c["Id"] == s["Id"]"

我们要做的就是给它拆箱,改为

where (int)c["Id"] == (int)s["Id"]

输出

Anthony's Class is: Freshman

上面人为的拆箱并不是很好的做法,所幸的是LiNQ为我们提供了泛型支持,看下面

注意,已经改成使用泛型的形式

where c.Field<int>("Id") == s.Field<int>("Id")


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics