views:

15

answers:

2

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
+1  A: 

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()
Justin Niessner
Yes all users have a matching ID in OpenIDs... thanks.
rockinthesixstring
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
@rockinthesixstring - Added it to the example. Glad it worked.
Justin Niessner
A: 
Dim user = dc.OpenIDs
    .Where(o => o.ClaimedIdentifier == claimedidentifier)
    .Select(o => o.User)

I'm partial to lambdas, myself...

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