我有以下 sql 查询,我正在尝试将其转换为 Linq,但无法使其完全正常工作。
select l.nid,
l.sName,
l.language,
coalesce(p.kLanguage, 0) kLanguage
from vLanguage l
left join
(
select pl.kLanguage,
p.nid,
p.sName
from vProductLanguage pl
left join vProduct p
on pl.kProduct = p.nid
where p.nid = 1
) p
on l.nid = p.kLanguage
where l.bClosed =0
我已经在我的 WCF 服务中做到了这一点
[WebInvoke(Method = "PUT", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "ProductLanguageList")]
public List<LookUpProductLanguage> GetProductLanguageList()
{
var passedProductId = int.Parse("12");
var query = from languageEntity in _languageEntityRepository.AsQueryable()
join subQueryResult in (from productLanguageEntity in _productLanguageEntityRepository.AsQueryable() join productEntity in _productRepository.AsQueryable() on productLanguageEntity.LanguageProductId equals productEntity.Id into joinedProductLanguage
from productLanguageJoin in joinedProductLanguage.DefaultIfEmpty() where productLanguageJoin.Id.Equals(passedProductId)
select new {LanguageId = productLanguageEntity.LanguageId}
) on languageEntity.Id equals subQueryResult.LanguageId
return null;
}
目前我已经返回 null 但希望返回 sql 查询中提到的列。我在 line join subQueryResult“无法从查询中推断出类型参数”附近收到错误。我在这是要干嘛?请纠正我,因为我确定我做错了什么。