Can't use .Union with Linq due to

前端 未结 2 1138
不思量自难忘°
不思量自难忘° 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 }
    );
    
    0 讨论(0)
  • 2021-01-04 08:46

    When I only look at your last try I see this:

    select new { x.NumLot, x.EtatLot, emp.NomEmploye };
    

    vs.

    select new { x.NumLot, x.EtatLot, test };
    

    You can never assign or cast one list of anonymous type to another as long as all their properties do not have equal type and name.

    EDIT: Write select new { x.NumLot, x.EtatLot, NomEmploye = test }; for the second one instead.

    0 讨论(0)
提交回复
热议问题