开发者

c# linq to sql join problem

开发者 https://www.devze.com 2022-12-31 21:25 出处:网络
i am trying to do using (UserManagementDataContext context = new UserManagementDataContext()) { var users = from u in context.Users

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.

what am i doing wrong?

table Users

ID  bigint
NameT开发者_如何学编程itle   nvarchar(64)
NameFirst   nvarchar(64)
NameMiddle  nvarchar(64)
NameLast    nvarchar(64)
NameSuffix  nvarchar(64)
Status  bigint
IsActive    bit

table 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.


UserEMailAdresses is a collection of email addresses, so it doesn't make sense to call EMailAddress on it.

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消