请将此LINQ C#转换为VB

时间:2011-03-23 16:04:45

标签: linq

您好 我发现这个代码在线,无法将其转换为vb。 如果有人将这个LINQ C#代码转换为VB,我真的很感激。 这是代码:

/// <summary>
/// 
/// </summary>
/// <returns></returns>
[DataObjectMethod(DataObjectMethodType.Select)]
public IEnumerable<Customer> FindByID(string id)
{
    //  find the customer
    return (from c in this.Customers where c.ID == id select c).ToList();
}

/// <summary>
/// 
/// </summary>
/// <param name="customer"></param>
public void Update(Customer newValues)
{
    //  simulate putting this record back into the database
    Customer oldValues = this.Customers.Find(x => x.ID == newValues.ID);

    oldValues.CompanyName = newValues.CompanyName;
    oldValues.ContactName = newValues.ContactName;
    oldValues.ContactTitle = newValues.ContactTitle;
    oldValues.Address = newValues.Address;
    oldValues.City = newValues.City;
    oldValues.State = newValues.State;
    oldValues.ZIPCode = newValues.ZIPCode;
    oldValues.Phone = newValues.Phone;
}

}

非常感谢你为我这样做。 马特

1 个答案:

答案 0 :(得分:1)

你应该可以使用:

<DataObjectMethod(DataObjectMethodType.[Select])> _
Public Function FindByID(id As String) As IEnumerable(Of Customer)
    '  find the customer
    Return (From c In Me.Customers Where c.ID = idc).ToList()
End Function

Public Sub Update(newValues As Customer)

    '  simulate putting this record back into the database
    Dim oldValues As Customer = Me.Customers.Find(Function(x) x.ID = newValues.ID)

    oldValues.CompanyName = newValues.CompanyName
    oldValues.ContactName = newValues.ContactName
    oldValues.ContactTitle = newValues.ContactTitle
    oldValues.Address = newValues.Address
    oldValues.City = newValues.City
    oldValues.State = newValues.State
    oldValues.ZIPCode = newValues.ZIPCode
    oldValues.Phone = newValues.Phone
End Sub