Question

I'm using .NET 4 and I'm just wondering if there is an optimized way of achieving the following.

    Public Function GetUserByOpenID(ByVal claimedidentifier As String) As User Implements IUserRepository.GetUserByOpenID
        Dim user = (From u In dc.Users
                    Where u.ID = (From o In dc.OpenIDs
                                  Where o.ClaimedIdentifier = claimedidentifier
                                  Select o.UserID).FirstOrDefault
                    Select u)
        Return user
    End Function
Was it helpful?

Solution

Assuming that all users have a matching ID in OpenIDs:

Dim user = (From u in dc.Users
            Join o in dc.OpenIDs On u.ID Equals o.UserId
            Where o.ClaimedIdentifier = claimedidentifier
            Select u).FirstOrDefault()

OTHER TIPS

Dim user = dc.OpenIDs
    .Where(o => o.ClaimedIdentifier == claimedidentifier)
    .Select(o => o.User)

I'm partial to lambdas, myself...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top