0

我的 sql 查询如下。

select st.kProductVersionPlatformFrom, st.kProductVersionPlatformTo, pv.kProduct, pv.nId, * 
from vSysTable st
left join vProductVersion pv on st.kProductVersionPlatformFrom = pv.nId  
where 
st.kProductVersionPlatformTo >= (select top 1 nid from vProductVersion where kProduct = 2
                                 and kProductVersionPlatform = 87 order by nId desc)

我正在尝试将其转换为 Linq,但找不到使用大于等于的方法

var systemTableList = (from sysTableEntity in _sysTableEntityRepository.AsQueryable()
                       join versionEntity in _productVersionRepository.AsQueryable() on
                           sysTableEntity.ProductVersionPlatformFrom equals versionEntity.Id
                           into leftjoined 
                           from joinedsysVersionTable in leftjoined.DefaultIfEmpty()
                           where (from versionEntity in _productVersionRepository.AsQueryable() 
                                  where versionEntity.ProductEntityId.Equals(2) && 
                                 versionEntity.PlatformProductVersionEntityId.Equals(87) 
                                  orderby versionEntity.Id descending 
                                  select versionEntity.Id).Take(1).Contains(sysTableEntity.ProductVersionPlatformFrom >= 87)
                       select new { sysTableEntity});

但是它在 Contains 关键字附近给我一个错误,即“无法从使用中推断出类型参数”

在这里使用什么而不是包含?我也尝试使用 Where 但仍然无法正常工作。

4

1 回答 1

1

因为子查询

select top 1 nid
from vProductVersion
where kProduct = 2
and kProductVersionPlatform = 87
order by nId desc

不相关,您可以单独使用它,然后在您的主查询中使用它的值。另外,您确定查询总是会返回值(不为空)吗?

var nid = from versionEntity in _productVersionRepository.AsQueryable()
where versionEntity.ProductEntityId.Equals(2) && 
versionEntity.PlatformProductVersionEntityId.Equals(87)
orderby versionEntity.Id descending
select versionEntity.Id).First();

然后使用这个:

var systemTableList =
     from sysTableEntity in _sysTableEntityRepository.AsQueryable()
       join versionEntity in _productVersionRepository.AsQueryable()
     on sysTableEntity.ProductVersionPlatformFrom equals versionEntity.Id
           into leftjoined
     from joinedsysVersionTable in leftjoined.DefaultIfEmpty()
     where ProductVersionPlatformTo >= nid;
于 2013-03-12T10:32:45.070 回答