0

我在使用选择时遇到问题。

IDE 不喜欢 () 中选择用户 ID 的选择查询。如何在选择中完成选择?

Dim newctx As teckModel.teckEntities
        Dim pending = From c In newctx.my_aspnet_membership Where c.userId = (From c In newctx.my_aspnet_usersinroles Where c.roleId = 8 Select c.userId) Select c.Email, c.CreationDate, c.LastLoginDate
4

2 回答 2

1

equals 运算符假定一个值,但第二个 linq 语句返回一个 IEnumerable。您应该.Contains()在 IEnumerable 上使用或进一步细化子查询以仅返回单个实体。

var pending = from x in newctx.my_aspnet_membership where
    (from y in newctx.my_aspnet_usersinroles where y.roleId==8 select y.userId).Contains(x.userId)
    select new { x.Email, x.CreationDate, x.LastLoginDate };
于 2012-09-23T22:52:38.183 回答
1

您可以执行ContainorAny或者您必须使用FirstOrDefault

Where (From c In newctx.my_aspnet_usersinroles Where c.roleId = 8 Select c.userId).Contains(c.userId)

或者

c.userId == (From c In newctx.my_aspnet_usersinroles Where c.roleId = 8 Select c.userId).FirstOrDefault()
于 2012-09-23T23:11:43.073 回答