为什么IEnumerable表现得很奇怪

时间:2011-03-22 13:59:59

标签: c# linq

我的代码如下:

var userTest =
    from u in userUpdated
    select (u.Field<string>("Emp Birthdate"));

var userTest1 = 
    from u in original
    select (u.Field<string>("Date of Birth"));

两个字段的值相同,即EmpBirthdate和出生日期,其为&#34; 1985年3月5日&#34;。

我使用以下代码给比较器:

IEnumerable<DataRow> records =
    from u in updateRecords
    join o in OriginalRecords
        on u.Field<string>("Employee ID")
        equals o.Field<int>(" Employee Identity No").ToString()
    where (u.Field<string>("Date of Birth") != 
        o.Field<string>("Emp Birthdate"))

它不匹配,上面的records.count()不等于0。

有什么问题?

提前致谢

1 个答案:

答案 0 :(得分:2)

你在用这种语法查询什么?

通常认为使用这样的字符串是不好的做法。强类型适配器会更好,并允许您访问u.EmployeeId而不是u.Field<string>("Employee ID")。我的猜测是,这种做法是导致问题的原因。也许您输入的字段名称不正确。我想不出任何字段名称会以" Employee Identity No"中的空格开头的情况。实际上,我根本无法想到空间被使用的情况。

然而,没有更多信息,没有人能够帮助你。我们需要知道您在查询什么,模式是什么样的,以及为什么您的语法看起来像这样。在没有提供的情况下,您将得到的最佳答案是,您问题的最可能原因是格式错误的魔术字符串。

相关问题