LINQ 中的减法
我有两张桌子: “人员”,包含 ID、姓名、... 列 和“用户”与人员ID(“人员”中ID列的FK),用户名,密码列
问题是如何查询其ID未在“用户”表中使用的人员实体,我的意思是来自“人员”的实体“用户”表中没有记录?
起初,我认为创建一个包含每个“人员”实体的视图,并在“用户”表中记录,并从所有人员实体中减去此视图,是解决方案,但我不知道如何在 Linq 中减去两个视图,
我使用了此查询对于视图:
from p in ObjectContext.personnels
join u in ObjectContext.users on p.ID equals u.PersonnelID
select p;
这是解决方案吗?如果是,我怎样才能减去两个视图?
或者有更好的方法吗?
PS!!:抱歉我的英语不好:D
I have two tables:
"Personnel" with ID,Name,... columns
and "User" with PersonnelID (FK of ID column in "Personnel"),Username,Password columns
The question is how can I query the personnel entities which their IDs are not used in "User" table, I mean entities from "Personnel" with no record in "User" table?
At first I thought creating a view containing each "Personnel" entity with record in "User" table and subtracting this view from all Personnel entities, is the solution, but I don't know how to subtract two views in Linq
I used this query for the view:
from p in ObjectContext.personnels
join u in ObjectContext.users on p.ID equals u.PersonnelID
select p;
Is this the solution? If yes how can I subtract two views?
Or is there a better way?
PS!!: Sorry for my bad english :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案:
尽管如此,您可能希望限制提取的列:
Answer:
Although, you might want to limit the columns that you pull: