0

嗨,我正在尝试加入 2 个数据表,左边的一个包含 3 个不同的列作为主键,另一个包含与外键相同的列,这是左边的数据表图像:

在此处输入图像描述

正确的 DataTable Imge 是这个:

在此处输入图像描述

这是我正在尝试使用的代码,但没有返回任何内容,它应该

var query5 =
        from ChanToNGrsToNgrDAnWal in chanToNGrsToNgrDAnWal.AsEnumerable()
        join Node in node.AsEnumerable() 
            on new { 
                 A = ChanToNGrsToNgrDAnWal.Field<int?>("diffusers_Id"), 
                 B = ChanToNGrsToNgrDAnWal.Field<int?>("analogs_Id"), 
                 C = ChanToNGrsToNgrDAnWal.Field<int?>("wallstats_Id") }
            equals new { 
                 A = Node.Field<int?>("diffusers_Id"), 
                 B = Node.Field<int?>("analogs_Id"), 
                 C = Node.Field<int?>("wallstats_Id") 
            }                  
        select new
        {
            channel_Id = ChanToNGrsToNgrDAnWal.Field<int?>("channel_Id"),
            number = ChanToNGrsToNgrDAnWal.Field<string>("number"),
            nodeGroups_Id = ChanToNGrsToNgrDAnWal.Field<int>("nodeGroups_Id"),
            analogNodeSerial = ChanToNGrsToNgrDAnWal.Field<string>("analogNodeSerial"),
            diffuserNodeSerial = ChanToNGrsToNgrDAnWal.Field<string>("diffuserNodeSerial"),
            wallStatNodeSerial = ChanToNGrsToNgrDAnWal.Field<string>("wallStatNodeSerial"),
            diffusers_Id = ChanToNGrsToNgrDAnWal.Field<int?>("diffusers_Id"),
            analogs_Id = ChanToNGrsToNgrDAnWal.Field<int?>("analogs_Id"),
            wallstats_Id = ChanToNGrsToNgrDAnWal.Field<int?>("wallstats_Id"),
            typeCode = Node.Field<string>("typeCode"),
            node_Id = Node.Field<int?>("node_Id")

        };

谁能告诉我为什么会这样或者我写的查询是错误的,请你们帮帮我。

4

1 回答 1

0

根据您的示例数据,您在这里没有任何匹配项(零与空值不匹配)。如果由于您的应用程序的逻辑这没问题,那么您可以将字段的值转换为int而不是Nullable<int>. 在这种情况下,将为DbNull单元格提供默认值(零):

    on new { 
         A = ChanToNGrsToNgrDAnWal.Field<int>("diffusers_Id"), 
         B = ChanToNGrsToNgrDAnWal.Field<int>("analogs_Id"), 
         C = ChanToNGrsToNgrDAnWal.Field<int>("wallstats_Id") 
    }
    equals new { 
         A = Node.Field<int>("diffusers_Id"), 
         B = Node.Field<int>("analogs_Id"), 
         C = Node.Field<int>("wallstats_Id") 
    }   
于 2013-06-19T12:28:58.453 回答