LINQ Query中的第二次连接导致没有记录返回

时间:2015-07-02 14:57:13

标签: c# linq

我正在尝试加入三个列表,但由于某种原因,第二个连接导致没有数据返回。我最终想要“离开”加入这个,但我正试图解决它没有正确加入的问题。

我的三个清单:

cbind(mydf["V1"], model.matrix(~V2 + 0, mydf))
##   V1 V2a V2b V2c
## 1  1   1   0   0
## 2  2   1   0   0
## 3  3   0   1   0
## 4  4   0   0   1
## 5  5   0   0   1

因此,请从var equipmentAliasList = new List<EquipmentAlias> { new EquipmentAlias { Alias = "100-00001"}, new EquipmentAlias { Alias = "100-00005"}, new EquipmentAlias { Alias = "100-00004"}, new EquipmentAlias { Alias = "100-00003"}, new EquipmentAlias { Alias = "100-00002"}, } var assets = new List<Asset> { new Asset { AssetNum = "100-00001", LineAsset = "200-00001"}, new Asset { AssetNum = "100-00005", LineAsset = "200-00002"}, new Asset { AssetNum = "100-00004", LineAsset = ""}, new Asset { AssetNum = "100-00003", LineAsset = "200-00001"}, new Asset{ AssetNum = "100-00002", LineAsset = ""}, }; var lineAssets = new List<Asset> { new Asset { AssetNum = " 200-00001", IsRunning = true }, new Asset { AssetNum = " 200-00002", IsRunning = false }, }; 上的equipmentAliasList加入assets中选择所有内容,然后加入assetNum上的lineAssets

以下是我的想法:

asset.LineAsset equals lineAsset.AssetNum

结果应该是:

(from e in equipmentAliasList
join ma in assets on e.Alias equals ma.AssetNum
join la in lineAssets on ma.LineAsset equals la.AssetNum
select new EquipmentAlias
{
    Alias = e.Alias,
    IsPor = la.IsRunning,
}).ToList();

但是,从 Alias | IsPor ----------|----------- 100-00001 | true 100-00005 | false 100-00003 | true assets的加入会导致查询不返回任何结果。

1 个答案:

答案 0 :(得分:3)

如果你注意到lineAssets,那么AssetNum字段中就有空格。将" 200-00001"更改为"200-00001"

var lineAssets = new List<Asset> {
    new Asset { AssetNum = "200-00001", IsRunning = true },
    new Asset { AssetNum = "200-00002", IsRunning = true },
};