开发者

How to do this in VB 2010 (C# to VB conversion)

开发者 https://www.devze.com 2022-12-30 18:01 出处:网络
I would like to have the following to be translated to VB 2010 (with advanced syntaxes) _domainContext.SubmitChanges(

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();

                 res开发者_高级运维ults.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


_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.

0

精彩评论

暂无评论...
验证码 换一张
取 消