我搜索了 StackOverflow,但仍然无法理解使用单一、第一(或默认)查询的正确语法。
我愿意先查询特定语言的翻译。如果数据库上没有这样的翻译,就拿第一个英文的。
这是我到目前为止得到的:
locale = "ja-jp";
var items = from c in db.Contents.Include("Translation")
where c.RegionalInfo.Any(x => x.RegionId == locale)
select c;
编辑 Obs.: items 是一个 IEnumerable
最佳答案
尝试这样的事情。
var item = (from c in db.Contents.Include("Translation")
where c.RegionalInfo.Any(x => x.RegionId == locale)
select c).FirstOrDefault();
if (item != null)
...
关于c# - 第一的?单例的?还是默认?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7325218/