views:

56

answers:

3

This C# code successfully gets the 2 relevant records into _currentUserRegisteredEventIds:

ctx.FetchEventsForWhichCurrentUserIsRegistered((op) =>
            {
                if (!op.HasError)
                {
                    var items = op.Value;
                    _currentUserRegisteredEventIds = new HashSet<int>(items);
                    UpdateRegistrationButtons();
                }
            }, null);

but VB code trying to do the same thing has nothing in _currentUserRegisteredEventIds:

ctx.FetchEventsForWhichCurrentUserIsRegistered(Function(op)
     If Not op.HasError Then
          Dim items = op.Value
          _currentUserRegisteredEventIds = New HashSet(Of Integer)(items)
          UpdateRegistrationButtons()
          End If
          End Function, Nothing)
        Else
            _currentUserRegisteredEventIds = Nothing
            UpdateRegistrationButtons()
        End If   

Any help appreciated.

A: 

Where's the second parameter for FetchEventsForWhichCurrentUserIsRegistered in the VB example? Are you calling a different overload?

David M
The FetchEventsForWhichCurrentUserIsRegistered has no parameters
Jim
@Jim, are you sure?
Andrey
Yes, the function in full is : Public Function FetchEventsForWhichCurrentUserIsRegistered() As IEnumerable(Of Integer) Dim mu As MembershipUser = Membership.GetUser() If mu Is Nothing Then Return New Integer(-1) {} End If Dim q = From attendeeEvent In Me.ObjectContext.AttendeeEvents Where attendeeEvent.Attendee.AspNetUserId = DirectCast(mu.ProviderUserKey, Guid) Select attendeeEvent.EventID Return q End Function
Jim
You're calling it with 2 parameters in C#, and at least one in your truncated VB. There must be overloads or extension methods with more parameters defined.
David M
C# code is from an SL4 training course; the FetchEventsForWhichCurrentUserIsRegistered is public IEnumerable<int> FetchEventsForWhichCurrentUserIsRegistered()So, no parameter
Jim
Step through your C# code in a debugger - check which FetchEventsForWhichCurrentUserIsRegistered method is actually called.
David M
I've done that in C# and VB; both correctly obtain the 2 relevant records.
Jim
@Jim: Do you really not see what David is saying? In the code you've posted, you are clearly passing two parameters to the method. This does not jive with what you are saying. There must be some detail you are leaving out; otherwise you are giving us contradictory information.
Dan Tao
A: 

You are missing the null / Nothing in the vb code

Fredou
he didn't show closing bracket in VB code, Nothing might got out of scope of vision
Andrey
Sorry, my original cut and paste was incomplete
Jim
A: 

I'm not sure if your code is formatted exactly as you have it printed here. I would think what you have above would not compile. See comments in code below:

ctx.FetchEventsForWhichCurrentUserIsRegistered(Function(op) 
     If Not op.HasError Then 
          Dim items = op.Value 
          _currentUserRegisteredEventIds = New HashSet(Of Integer)(items) 
          UpdateRegistrationButtons() 
          End If  ' End if of the main conditional
          End Function, Nothing)  ' End of the function
        Else   ' What is this else doing here? It seems to be orphaned
            _currentUserRegisteredEventIds = Nothing 
            UpdateRegistrationButtons() 
        End If 

I would think it would need to look a little more like:

ctx.FetchEventsForWhichCurrentUserIsRegistered(Function(op) 
     If Not op.HasError Then 
          Dim items = op.Value 
          _currentUserRegisteredEventIds = New HashSet(Of Integer)(items) 
          UpdateRegistrationButtons() 

        Else 
            _currentUserRegisteredEventIds = Nothing 
            UpdateRegistrationButtons() 
        End If
    End Function, Nothing) 
Joel Etherton