Hacer una combinación de modo que solo se devuelva la primera fila

I have a case of Linq, where upon joining two tables, I'm getting 10 rows of data. But I really care about the first one, is there a way to limit it to return only 1 row?

Is there a general join operation like this? For example, is there something like FIRST OUTER JOIN, or something ...?

preguntado el 31 de enero de 12 a las 16:01

You do the join as you normally would, then do a First() or FirstOrDefault() right after. -

@BrokenGlass - In order for that to return the expected results, he better be specifying an Order en algún lugar... -

True that - unless he doesn't care about the order and wants just "any" - unlikely though. No order was specified in the question though -

1 Respuestas

var result = (<your query>).First();

Or if you want to guard against an empty sequence;

var result = (<your query>).FirstOrDefault();

Respondido 01 Feb 12, 13:02

Strictly speaking, FirstOrDefault doesn't guard against null... it guards against empty sequence. - Thomas Levesque

Good point, I was thinking of whenever you actually try to access your result, but I guess it's not like you would ever get there if you used First() on an empty sequence. Will update the wording - cheers. - Chris McAtackney

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.