在数据实体asp中使用not exist在嵌套的选定语句中

本文关键字:嵌套 语句 exist 数据 实体 asp not | 更新日期: 2023-09-27 18:02:33

我是ASP新手。. NET和我试图写一个查询是没有问题的SQL,但我不能在c#。

我有两个表:


t_id(初级)
t_desc

TownCounty
Tc_id (primary)
Co_id(县id)
T_id(来自城镇表)
t_active (Y/N)

我想做的是显示所有未分配给特定县(co_id)的城镇(即。"DUB"),如果它们被分配到那个县,如果它们不是活动的,则显示它们(t_active = "N")。

在SQL中,我写了下面的语句,效果很好

select a.t_desc as "Town " from town a
where not exists(
select * from  towncounty b where 
b.co_id like "DUB" and 
b.t_active = "Y" and
b.t_id = a.t_id)

现在我正试图让它在ASP工作。NET (c#)。我写了下面的声明,但可惜没有用:

IEnumerable<Town> Towns = (from co in handyman.townCounties
where co.co_id != county_id || t_active = "N" 
join to in handyman.towns on co.t_id equals to.t_id into coto 
from subcoto in coto.DefaultIfEmpty() 
select new Town 
{ 
   Id = subcoto.t_id, <br/>
   Name = subcoto.t_desc <br/>
}); 

试图做一个左连接,但返回一个混乱。

在数据实体asp中使用not exist在嵌套的选定语句中

我整理了这个年龄以前,但不记得我现在做了什么,不再有代码,只是想关闭这个问题,抱歉没有帮助