LINQ Question - Query -


I have a table which for example stores a cultural form for a particular key.

 RecordID Key CultureID Description 1 1 NG-B Hour 2 1 SS-ESHara 3 2 NBG Swimming 

I have been given this as an IEnumerable @ cultureID = "ES- I want to return the parameter of "ES" to the following In short, if the cultural version is present then return it to the given parameter, and then return the "N-GB" entry (which are present), can anyone help me with the LINQ query for this

 RecordID Key CultureID Description 2 1 es-ES Hora 3 2 n-gb swimming 

thanks

You can use the fact that booolans sort in [false, true], so the following quer not the same en-GB , and then en-GB .

  var result = (where x.CultureID == cultureID = x.CultureID == "N-GB" order by x.Culture ID == "N-GB" x in variant in x Select) first ();  

If no "N-GB" entry is present for any key ( first is a demand for at least one record) then this query is an error Will, but you said, it is always present if you are not sure, use first and default .

Note that many LINQ providers support these idioms, it is not only usable for IEnumerable / lists. You can also add filters to key and culture as part of the LINQ query, so that you can sort the database for you, and you will not get a complete list of translations that you want to:

  var result = (in X in DB. Translation where x.Key == some key & amp; (x.CultureID == cultureID || x.CultureID == "en-GB") Order B X. CultureEdit == "N-GB" Select X) first ();  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -