Comment puis-je convertir l'instruction SQL suivante en une instruction LinqToSQL?Convertir une instruction SQL en Linq
select field, 1 as ordering from table where field2 = condition1
union all
select field, 7 as ordering from table where field2 = condition2
union all
select field, 3 as ordering from table where field2 = condition3
union all
select field, 2 as ordering from table where field2 = condition4
order by ordering
En effet, je rejoins juste quelques requêtes et je commande le jeu de résultats en fonction de l'origine de la ligne.
Je peux gérer l'union, comme ci-dessous, mais je n'arrive pas à obtenir LinqToSQL pour commander l'ensemble des résultats, je peux seulement l'obtenir pour commander chaque requête individuelle.
from t in table
where
condition
select new { field, ordering = 1 }
).Union
(
from t2 in table2
where
condition
select new { field ordering = 7 }
).Union
(
from t3 in table3
where
condition
select new { field ordering = 3 }
).Union
(
from t4 in table4
where
condition
select new { field ordering = 2 }
);
C'est exactement ce que je recherchais - merci. – user9659