2011-03-23 173 views
0

嗨 我在線上發現此代碼,無法將其轉換爲vb。 我真的很感激,如果有人會將這個LINQ C#代碼轉換爲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

您應該能夠使用:

<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