Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
More Linq Blues (update - found solution).
Message
 
À
Tous
Information générale
Forum:
C#
Catégorie:
LINQ
Titre:
More Linq Blues (update - found solution).
Divers
Thread ID:
01673494
Message ID:
01673494
Vues:
89
I have this SQL
SELECT * FROM PARCELS PA,transactiondetails,emtransactions
where pa.Parcels_Id = transactiondetails.Parcels_Id
and transactiondetails.TransactionHeaders_Id = emTransactions.TransactionHeaders_Id
and emtransactions.Document = 'PF180160'
and exists(select * from PARCELS PB,transactiondetails,emtransactions
where pb.Parcels_Id = transactiondetails.Parcels_Id
and transactiondetails.TransactionHeaders_Id = emTransactions.TransactionHeaders_Id
and emtransactions.Document = 'PFR190099'
and PA.Parcels_Id = PB.Parcels_Id)
order by RSReference
that returns the expected results.
Whereas my best shot at translating this into Linq
var parcels = Parcels
	.Join(TransactionDetails, p => p.Parcels_Id, t => t.Parcels_Id, (p, t) => new { p, t })
	.Join(EMTransactions, d => d.t.TransactionHeaders_Id, e => e.TransactionHeaders_Id, (d, e) =>new  { d,e})
	.Where(x => x.e.Document == "PF180160")
	.Where(x => x.d.p.Parcels_Id ==
		Parcels
			.Join(TransactionDetails, p2 => p2.Parcels_Id, t2 => t2.Parcels_Id, (p2, t2) => new { p2, t2 })
			.Join(EMTransactions, d2 => d2.t2.TransactionHeaders_Id, e2 => e2.TransactionHeaders_Id, (d2, e2) => new { d2, e2 })
			.Where(z => z.e2.Document == "PFR190099")
			.FirstOrDefault().d2.p2.Parcels_Id)
does not.
This on the other hand ...
var parcels = Parcels
	.Join(TransactionDetails, p => p.Parcels_Id, t => t.Parcels_Id, (p, t) => new { p, t })
	.Join(EMTransactions, d => d.t.TransactionHeaders_Id, e => e.TransactionHeaders_Id, (d, e) =>new  { d,e})
	.Where(x => x.e.Document == "PF180160")
	.Where(x => Parcels
			.Join(TransactionDetails, p2 => p2.Parcels_Id, t2 => t2.Parcels_Id, (p2, t2) => new { p2, t2 })
			.Join(EMTransactions, d2 => d2.t2.TransactionHeaders_Id, e2 => e2.TransactionHeaders_Id, (d2, e2) => new { d2, e2 })
			.Where(z => z.e2.Document == "PFR190099")
			.Any(z => z.d2.p2.Parcels_Id == x.d.p.Parcels_Id))
... does :)

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Répondre
Fil
Voir

Click here to load this message in the networking platform