Can't use .Union with Linq due to

前端 未结 2 1137
不思量自难忘°
不思量自难忘° 2021-01-04 08:12

I\'m kind of stuck with that problem. Hope i\'ll get some help. Here\'s the point. I have to fill my DataGridView with that SQL request :

SELECT LOT.NumLot,          


        
2条回答
  •  醉梦人生
    2021-01-04 08:39

    The problem is that your anonymous types are not the same type.

    One is { ? NumLot, ? EtatLot, string NomEmploye } and the other is { ? NumLot, ? EtatLot, string test }. The last member has a different name hence it is a different type.

    Try this instead:

    var listeLotControle =
    (
        from x in entBoum.LOT
        join aff in entBoum.AFFECTATION_LOT on x.NumLot equals aff.NumLot
        join emp in entBoum.EMPLOYE on aff.IdEmploye equals emp.IdEmploye
        where x.EtatLot.Contains("Libéré") || x.EtatLot.Contains("Suspendu") || x.EtatLot.Contains("Démarré")
        select new { x.NumLot, x.EtatLot, emp.NomEmploye }
    ).Union
    (
        from x in entBoum.LOT
        where x.EtatLot.Contains("Démarré")
        select new { x.NumLot, x.EtatLot, NomEmploye = test }
    );
    

提交回复
热议问题