LINQ查询忽略所有重复的ID [英] LINQ Query that omits any duplicate IDs
问题描述
我有两个桌子.为了简单起见,将它们称为表A和表B,
I have two tables. For simplistic reasons will call them Table A and Table B,
表A:
ID int(PK)
客户名称 varchar
customeraddy varchar
服务中 布尔值
等 varchar
等 varchar
表B:
PKID int(PK)
ID int()
线路名称 varchar
linename varchar
只需寻找一个LINQ查询,即可从ID列(其中inservice =="true")的表A 和表B 的联接表中选择所有值忽略基于ID的任何重复项(因为表B具有ID的多个重复项).
Just looking for a LINQ query that can select all values from a joined table of Table A and Table B on the ID column where inservice == "true" that omits any duplicates based on ID (because Table B has multiple duplicates of ID).
到目前为止,这就是我所拥有的:
So far this is what i have:
from x in db.tableA
join y in db.tableB on x.id equals y.id
where x.inservice == "true"
select y);
推荐答案
假定表中的inservice
是bool
而不是string
,并假设您同时希望tableA和tableB行,其中tableB只有一个匹配行,
Assuming inservice
is bool
as in your table description and not string
, and assuming you want both tableA and tableB rows where tableB has only one matching row,
var AjoinB = from x in db.tableA
where x.inservice
join y in db.tableB on x.id equals y.id
group new { x, y } by x.id into xyg
where xyg.Count() == 1
select xyg;
这篇关于LINQ查询忽略所有重复的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!