如何为少于操作创建Linq to Entities子查询

时间:2014-03-11 10:43:38

标签: linq-to-entities

如何在sql中编写以下Linq to Entities

select * from LanguageApplicationResource as outside 
where LanguageId = 130 and 
      LastUpdatedOn < (select LastUpdatedOn from LanguageApplicationResource 
                       where LanguageId = 75 and 
                       ApplicationResourceId = outside.ApplicationResourceId)

我尝试了这个,但它用Unable to create a constant value of type 'xxxx'轰炸了,这是有道理的,但我无法弄清楚Linq to Entities方式。

var pendingList = LanguageApplicationResourceRepo.Table.Where(a => a.LanguageId == language.LanguageId &&
a.LastUpdatedOn < LanguageApplicationResourceRepo.Table.Where(b => b.LanguageId == defaultLanguage.LanguageId && 
b.ApplicationResourceId == a.ApplicationResourceId).FirstOrDefault().LastUpdatedOn).ToList();

1 个答案:

答案 0 :(得分:0)

试试这个:

var query = dbContext.LanguageApplicationResource
    .Where(u => LanguageId == 130 &&
                dbContext.LanguageApplicationResource
                     .Where(t => t.LanguageId == 75 &&
                                 t.ApplicationResourceId = u.ApplicationResourceId)
                     .Take(1)
                     .All(t => u.LastUpdatedOn < t.LastUpdatedOn)
          )
    .ToList();