[英]c# linq to sql join problem
i am trying to do 我想做
using (UserManagementDataContext context = new UserManagementDataContext())
{
var users = from u in context.Users
where u.UserEMailAdresses.EMailAddress == "email@example.com"
select u;
return users.Count();
}
however, when i get to: 但是,当我到达:
using (UserManagementDataContext context = new UserManagementDataContext())
{
var users = from u in context.Users
where u.UserEMailAdresses.
i do not get offered the EMailAddress name, but rather some neutral default-looking list of options in intelisense. 我没有得到EMailAddress名称,而是intelisense中一些中性的默认外观选项列表。
what am i doing wrong? 我究竟做错了什么?
table Users 表用户
ID bigint
NameTitle nvarchar(64)
NameFirst nvarchar(64)
NameMiddle nvarchar(64)
NameLast nvarchar(64)
NameSuffix nvarchar(64)
Status bigint
IsActive bit
table UserEMailAddresses 表UserEMailAddresses
ID bigint
UserID bigint
EMailAddress nvarchar(256)
IsPrimary bit
IsActive bit
obviously, 1 user can have many addresses and so Users.ID
and UserEMailAddresses.UserID
have a relationship between them: 1 to MANY. 显然,1个用户可以有多个地址,因此Users.ID
和UserEMailAddresses.UserID
之间存在关系:1到MANY。
UserEMailAdresses
is a collection of email addresses, so it doesn't make sense to call EMailAddress
on it. UserEMailAdresses
是电子邮件地址的集合,因此在其上调用EMailAddress
没有任何意义。
You have to check if there is an email address in the collection that matches the one you're looking for : 您必须检查集合中是否有与您要查找的电子邮件地址匹配的电子邮件地址:
var users = from u in context.Users
where u.UserEMailAdresses.Any(e => e.EMailAddress == "email@example.com")
select u;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.