Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First? Single? Or Default?

I've searched StackOverflow but still cannot understand the correct syntax to use Single, First (or default) queries.

I'm willing to make a query to catch first the translation in specific language. If there is no such translation on the db, get the first one in English.

Here is what I got so far:

locale = "ja-jp";

var items = from c in db.Contents.Include("Translation")
            where c.RegionalInfo.Any(x => x.RegionId == locale)
            select c;

Edit Obs.: items is an IEnumerable

like image 744
programad Avatar asked Sep 06 '11 19:09

programad


1 Answers

Try something like this.

var item = (from c in db.Contents.Include("Translation")
        where c.RegionalInfo.Any(x => x.RegionId == locale)
        select c).FirstOrDefault();
if (item != null)
   ...
like image 145
Jonathan Wood Avatar answered Oct 06 '22 12:10

Jonathan Wood