views:

71

answers:

1

I would like to have the following to be translated to VB 2010 (with advanced syntaxes)


_domainContext.SubmitChanges(
     submitOperation =>
     {
        _domainContext.Load<Customer>(
             _domainContext.GetCustomersQuery(),
              LoadBehavior.RefreshCurrent,
              loadOperation =>
              {
                 var results = _domainContext.Customers.Where(
                         entity => !loadOperation.Entities.Contains(entity)).ToList();

                 results.ForEach( enitity => _domainContext.Customers.Detach(entity));
              }, null);
      }, null);

I managed to get the above with other ways (but not using anonymous methods). I would like to see all the advanced syntaxes available in VB 2010 to be applied to the above.

Can anyone help me on this?

thanks

A: 
_domainContext.SubmitChanges(
    Sub(submitOperation)
        _domainContext.Load<Customer>(
            _domainContext.GetCustomersQuery(),
            LoadBehavior.RefreshCurrent,
            Sub(loadOperation)
                Dim results = _domainContnext.Customers.Where(
                                Function(entity) Not loadOperation.Entities.Contains(entity)) _
                                .ToList();
                results.ForEach(Sub(entity) _domainContext.Customers.Detach(entity))
            End Sub,
            Nothing)
    End Sub, Nothing)

I obviously couldn't put that into a compiler, but that should get you in the right direction. Basically, anywhere you see a => in the C#, you will replace with an inline Sub or Function depending on if a value needs to be returned. If there are braces in the C# lambda, you will end up with a multi-line Sub/Function in VB. Note that you can only do this in VB2010 as VB08 did not support Sub lambdas or multi-line Function lambdas.

Gideon Engelberth