私は ASP.NET を初めて使用し、SQL では問題ないクエリを作成しようとしていますが、C# では実行できません。
私は2つのテーブルを持っています:
町
t_id (プライマリ)
t_desc
TownCounty
tc_id (プライマリ)
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/>
});
左結合をしようとしていますが、混乱を返します。どんな助けでも大歓迎です。