0

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

2 Answers 2

1

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()
Sign up to request clarification or add additional context in comments.

2 Comments

All I had to add to your example was .FirstOrDefault so that I could get a single record returned. Thank you for the help.
@rockinthesixstring - Added it to the example. Glad it worked.
0
Dim user = dc.OpenIDs
    .Where(o => o.ClaimedIdentifier == claimedidentifier)
    .Select(o => o.User)

I'm partial to lambdas, myself...

1 Comment

I'm with you there...but this example is VB.NET. No Lambdas for them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.